题目链接

题意 : 这个人需要做n道菜,每道菜Ai步,他可以同时做M道不同的菜的其中一步,问你最少需要多少时间能做完所有的菜。

思路 : 这个题比赛的时候禁锢思路了,根本没想出来,就是当M > N时,需要的时间一定是N道菜里边步骤最多的那道菜的步骤数。如果不是就判断平均需要的时间,如果平均需要的时间不如最多步骤多,那还是步骤数,否则就是平均时间。

 1 #include <iostream>
 2 #include <stdio.h>
 3 #include <string.h>
 4 
 5 using namespace std;
 6 
 7 int a[40010] ;
 8 
 9 int main()
10 {
11     int n,t,m ;
12     scanf("%d",&t);
13     while(t--)
14     {
15         scanf("%d %d",&n,&m) ;
16         int sum = 0 ;
17         int maxx = 0 ;
18         for(int i = 1 ; i <= n ; i++)
19         {
20             scanf("%d",&a[i]) ;
21             sum += a[i] ;
22             maxx = max(maxx,a[i]) ;
23         }
24         int temp = sum/m ;
25         if(sum % m)
26             temp++ ;
27         if(temp <= maxx)
28             temp = maxx ;
29         printf("%lld\n",temp) ;
30     }
31     return 0;
32 }
View Code

 

posted on 2014-04-15 21:08  枫、  阅读(267)  评论(0编辑  收藏  举报