ZOJ 3778 talented Chef (math AH)

Source: Internet
Author: User

Title Link: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5017


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
Author:JIANG, Kai
Source:The 11th Zhejiang Provincial Collegiate Programming Contest


Test instructions

There are a total of n-course dishes each need a fixed time to complete, a person can choose at the same time M-course dishes to do at the same time!

Ask for at least how many minutes to finish all the dishes!

The code is as follows:

#include <stdio.h> #include <stdlib.h> #include <string.h> #include <limits.h> #include < malloc.h> #include <ctype.h> #include <math.h> #include <string> #include <iostream># Include <algorithm>using namespace std, #include <stack> #include <queue> #include <vector># Include <deque> #include <set> #include <map> #define INF 999999999#define EPS 0.00001#define LL __ Int64d#define Pi ACOs ( -1.0) int main () {int t;scanf ("%d", &t), while (t--) {int I, J;int n, m;int sum = 0;int tt, Maxx = 0;s CANF ("%d%d", &n,&m); for (i = 0; i < n; i++) {scanf ("%d", &tt), Sum+=tt;if (TT > Maxx) {maxx = TT;}} int ans = sum/m;if (sum%m! = 0) {ans+=1;} if (Ans < Maxx) {ans = maxx;} printf ("%d\n", ans);} return 0;} /*3 9992 2 210 9991 2 3 4 5 6 7 8 9 10*/

ZOJ 3778 talented Chef (math AH)

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: info-contact@alibabacloud.com 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.