Description Kwong Slamdunk is a life winner, rumor has it that he is now about to have a girlfriend, and in the emotional drive he even began to learn to cook! Now he wants to do N-course for girlfriend, every dish to do it needs AI minutes, slamdunk a minute can cook M-course, ask him to finish this N-course meal the shortest time is how much? (If you can help him solve this problem, he and his girlfriend will give you a beautiful balloon ~) input the first line to enter an integer t indicates that the test data in total T (1 <= t <=10) group the first row of each set of test data has a positive integer n (1 <= N <= 10000) and a positive integer M (1 <= m <= 10000) The second line has n positive integers a1,a2 .... An (1 <= Ai <= 10000) indicates the time required to make each dish output a number for each set of data, representing the shortest time required to finish the N-course sample Input2 3 2 2 2 2 ten 6 1 2 3 4 5 6 7 8 9Sample Output3 TenHINT
The main idea: compare the average and the maximum value, see the new skills Get ~ ~ ~ To find the threshold aver= (aver+m-1)/m, you do not need to use the mark is not the whole except.
#include <cstdio>#include<cstring>#include<algorithm>using namespacestd;intMain () {intt,n,m; intMax,aver,num; scanf ("%d",&t); while(t--) {aver=max=0; scanf ("%d%d",&n,&m); while(n--) {scanf ("%d",&num); Max=Max (max,num); Aver+=num; } aver= (aver+m-1)/m; printf ("%d\n", Max (Aver,max)); } return 0;}
View Code
Guang Gong School race--slamdunk is cooking