Guang Gong School race--slamdunk is cooking

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.