C - Talented Chef ZOJ - 3778

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
#include<cstdio>
#include<cstring>
#include<algorithm>
typedef long long ll;
using namespace std;

/*
心态还算可以吧,这次总归有点思路,不至于一点都没有,脑子里面有灵感,但是还是差点练习吧,错过了很多
1.我当时考虑到应该是sum/n(+1),然后队友抛给了我一组 1 1  6,当时就发现完了,我们的结论不对,但是忘记了
 我们的一个适用范围,也就是说我们的猜测,并不是直接就是全部答案,尤其是对于像后面这种捣鼓了半天的题
 更有可能是是每一个小点最后凑出来的答案,还是积累经验吧 
 最大值,在某种情况下是最大,但是在某种情况下也是最小(我们的次数不可能小于这个max_val 
*/

int main(){
	
	int T;
	scanf("%d",&T);
	while(T--){
		int n,m;
		scanf("%d %d",&n,&m);
		ll sum=0,max_=0;
		for(int i=1;i<=n;i++){
			ll val;
			scanf("%lld",&val);
			sum+=val;
			max_=max(max_,val);
		}
		ll ans=sum/m;
		if(sum%m)ans++;
		ans=max(ans,max_);
		printf("%lld\n",ans);
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_36424540/article/details/80057513
ZOJ