Description
As we all know, Coach Gao was a talented chef, because he was able to cook M dishes in the same time. Tonight he is going to has a hearty dinner with his girlfriend at his home. Of course, Coach Gao is going-cook all dishes himself, in order-show off his genius cooking skill to his GI Rlfriend.
To make full use of the He genius in cooking, Coach Gao decides to prepare dishes for the N dinner. The i -th dish contains Ai steps. The steps of a dish should be finished sequentially. In all minute of the cooking, Coach Gao can choose at most M different dishes and finish one step to each D Ish chosen.
Coach Gao wants to know the least time he needs to prepare the dinner.
Input
There is multiple test cases. The first line of input contains an integer indicating the number of the T test cases. For each test case:
The first line contains integers N M and (1 <= N , M <= 40000). The second line contains N integers Ai (1 <= Ai <= 40000).
Output
For each test case, the output of the least time (in minute) to finish all dishes.
Sample Input
23 22 2 210 61 2 3 4 5 6 7 8 9 10
Sample Output
310
Source
This could be a total of 40000 courses, even if I use the quick row, the complexity is particularly high
First line Input test Case number T
The second line is the number of dishes the chef cooks, and the number of dishes that can be done at the same minute.
Ask the chef to finish these dishes in the shortest time
My timeout code is as follows
#include <stdio.h>#include<algorithm>#include<string.h>using namespacestd;BOOLcmpintAintb) { returnA >b;}intMain () {intT, d[40010]; scanf ("%d",&t); while(t--) { intN, m, cnt =0; scanf ("%d%d", &n, &m); memset (d,0,sizeof(d)); for(inti =0; I < n; i++) scanf ("%d", &D[i]); Sort (d, D+N, CMP); while(d[0] !=0) { for(inti =0; D[i]! =0&& i < m; i++) {D[i]--; } sort (d, D+N, CMP); CNT++; } printf ("%d\n", CNT); }}
The comparison function to be used by the sort function in the upper code I always write wrong, remember is return a > b;
Later found not so troublesome, anyway, my mind is not a moment to let the chef idle (every minute is the sort is the reason), can fully play the skills to let him fully play the skills, so put (the sum of the steps of all dishes)/(chef can do the number of dishes per minute) + (all dishes of the sum of steps)% (Chef cooks up to the maximum number of dishes per minute) compared to the number of steps in the number of steps, the larger is the result
So much simpler, nature will not time out, the original is I think more ah, haha
#include <stdio.h>intMain () {intT; scanf ("%d", &t); while(t--) { intN, m, sum =0, Maxd =0, A; scanf ("%d%d", &n, &m); for(inti =0; I < n; i++) {scanf ("%d", &a); if(A >maxd) Maxd=A; Sum+=A; } A= SUM/m; if(Sum%m) a++; if(A >maxd) printf ("%d\n", a); Elseprintf ("%d\n", Maxd); } return 0;}
Talented Chef (simple question, I think is too complex, with a complex method of course, it will time out, it can be seen, not all the questions are thinking the more the better)