slamdunk正在做菜

Description

广工的slamdunk可谓是人生赢家,据传说他现在即将拥有一个girlfriend,并且在感情的驱使下他甚至开始学起了做菜! 现在他想为girlfriend做N道菜,每道菜做出来需要Ai分钟,slamdunk一分钟最多能煮M道菜,请问他做完这N道菜所需的最短时间 是多少?(如果你能帮他解决这个问题,他和他的girlfriend会送给你一个精美的气球~)

Input

第一行输入一个整数T表示测试数据共有T(1 <= T <=10)组 每组测试数据的第一行有一个正整数N(1 <= N <= 10000)和一个正整数M(1 <= M <= 10000) 第二行有N个正整数A1,A2....An(1 <= Ai <= 10000)表示做出每道菜所需的时间

Output

每组数据输出一个数字,代表做完这N道菜所需的最短时间

Sample Input

2 3 2 2 2 2 10 6 1 2 3 4 5 6 7 8 9 10

Sample Output

3 10

HINT

 就是浙江省省赛的一道题,贪心。因为一分钟最多能煮M道菜,所以每分钟菜的分钟总值都可以-M

但需要找出菜中花费时间最长的,因为最终花费的时间肯定大于等于这个时间。

 1 #include <iostream>
 2 #include <cstring>
 3 #include <cstdio>
 4 #include <string>
 5 #include <algorithm>
 6 using namespace std;
 7 int T, n, k;
 8 #define maxn 10010
 9 int a[maxn];
10 int main(){
11     scanf("%d", &T);
12     while(T--){
13         scanf("%d%d", &n, &k);
14         int sum = 0;
15         int Max = 0;
16         for(int i = 1; i <= n; i++){
17              scanf("%d", &a[i]);
18              sum += a[i];
19              if(a[i] > Max) Max = a[i];
20         }
21         int ans;
22         if(sum%k == 0) ans = sum/k;
23         else ans = sum/k+1;
24         printf("%d
",Max>ans?Max:ans);
25         
26     }
27     
28     return 0;
29 }
原文地址:https://www.cnblogs.com/titicia/p/4342027.html