zoj 3778 Talented Chef

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5265

先确定n和m的大小,m大就输出最大值就可以。否则比较sum/m和max1的大小。

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <algorithm>
 4 using namespace std;
 5 
 6 int main()
 7 {
 8     int t;
 9     scanf("%d",&t);
10     while(t--)
11     {
12         int n,m;
13         scanf("%d%d",&n,&m);
14         int sum=0,max1=0;
15         for(int i=1; i<=n; i++)
16         {
17             int x;
18             scanf("%d",&x);
19             sum+=x;
20             max1=max(max1,x);
21         }
22         int ans=0;
23         if(sum%m)
24         {
25             ans=sum/m+1;
26         }
27         else
28             ans=sum/m;
29         if(max1>ans)
30             ans=max1;
31         if(n>=m)
32         {
33             printf("%d\n",ans);
34         }
35         else
36         {
37             printf("%d\n",max1);
38         }
39     }
40     return 0;
41 }
View Code

 

posted @ 2014-11-02 15:28  null1019  阅读(165)  评论(0编辑  收藏  举报