0
点赞
收藏
分享

微信扫一扫

ZOJ3778 C - Talented Chef

嚯霍嚯 2022-06-29 阅读 45

As we all know, Coach Gao is a talented chef, because he is able to cook M dishes in the same time. Tonight he is going to have a hearty dinner with his girlfriend at his home. Of course, Coach Gao is going to cook all dishes himself, in order to show off his genius cooking skill to his girlfriend.
To make full use of his genius in cooking, Coach Gao decides to prepare N dishes for the dinner. The i-th dish contains Ai steps. The steps of a dish should be finished sequentially. In each minute of the cooking, Coach Gao can choose at most M different dishes and finish one step for each dish chosen.
Coach Gao wants to know the least time he needs to prepare the dinner.
Input
There are multiple test cases. The first line of input contains an integer T indicating the number of test cases. For each test case:
The first line contains two integers N and M (1 <= N, M <= 40000). The second line contains N integers Ai (1 <= Ai <= 40000).
Output
For each test case, output the least time (in minute) to finish all dishes.
Sample Input
2
3 2
2 2 2
10 6
1 2 3 4 5 6 7 8 9 10
Sample Output
3
10 借用一大神的想法
思路;N个菜,每个菜有ai个步骤,每次可以同时做m个菜的第一步,问最少需要花费多少时间。
分类讨论即可;
若n>m,则用总的步骤除以每次可以减去的步数,如果不可以整除,则使结果加一,然后再与最大的步骤数去比较,因为总天数一定是要大于最大步骤数的,那么最后一定要输出最大的那一个。
如果n<=m,那么直接输出最大的步骤数即可。

#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int maxn=-1;
int n,m;
int i;
int a;
long long sum=0;
scanf("%d%d",&n,&m);
for(i=0;i<n;i++)
{
scanf("%d",&a);
sum+=a;
maxn=max(maxn,a);
}
if(sum%m)
{
sum=sum/m+1;//如果有余数,说明没能完全整除,那么天数+1
}
else
sum=sum/m;
if(sum>maxn)
printf("%lld\n",sum);//与步骤最多的进行比较
else if(sum<=maxn)
printf("%d\n",maxn);
}
return 0;
}


举报

相关推荐

0 条评论