As we all know, Coach Gao is a talented chef, because he is able to cook M dishes in the same time. Tonight he is going to have a hearty dinner with his girlfriend at his home. Of course, Coach Gao is going to cook all dishes himself, in order to show off his genius cooking skill to his girlfriend.

To make full use of his genius in cooking, Coach Gao decides to prepare N dishes for the dinner. The i-th dish contains Ai steps. The steps of a dish should be finished sequentially. In each minute of the cooking, Coach Gao can choose at most Mdifferent dishes and finish one step for each dish chosen.

Coach Gao wants to know the least time he needs to prepare the dinner.

Input

There are multiple test cases. The first line of input contains an integer Tindicating the number of test cases. For each test case:

The first line contains two integers N and M (1 <= NM <= 40000). The second line contains N integers Ai (1 <= Ai <= 40000).

Output

For each test case, output the least time (in minute) to finish all dishes.

Sample Input

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

Sample Output

3
10

题目大意:一个人可以在一分钟同时进行m道菜的一个步骤,共有n道菜,每道菜各有xi个步骤,求做完的最短时间。

思维题,以平均值来做菜,所用的时间总是最短。

// Asimple
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <queue>
#include <vector>
#include <string>
#include <cstring>
#include <stack>
#define INF 0x3f3f3f3f
#define mod 7
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = +;
int n, m, T, len, cnt, num; void input() {
cin >> T;
while( T -- ) {
cin >> n >> m;
int Max = ;
int sum = ;
for(int i=; i<n; i++) {
cin >> num;
sum += num;
Max = max(Max, num);
}
cnt = sum/m;
if( sum%m ) cnt ++;
if( cnt < Max ) cnt = Max;
if( m >= n ) cout << Max << endl;
else cout << cnt << endl;
}
} int main() {
input();
return ;
}

Talented Chef ZOJ - 3778的更多相关文章

  1. ZOJ 3778:Talented Chef(贪心?思维)

    Talented Chef Time Limit: 2 Seconds Memory Limit: 65536 KB As we all know, Coach Gao is a talented c ...

  2. Talented Chef(简单题,被我想的太复杂了,用复杂的方法当然会超时咯,由此可见,并非所有题都是想的越多越好)

    Description As we all know, Coach Gao is a talented chef, because he is able to cook M dishes in the ...

  3. zoj3778 Talented Chef

    As we all know, Coach Gao is a talented chef, because he is able to cook M dishes in the same time. ...

  4. ZOJ 3778 C - Talented Chef 水题

    LINK:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3778 题意:有n道菜,每道菜需要\(a_i\)道工序,有m个锅可 ...

  5. ZOJ 3778 Talented Chef(找规律,模拟计算,11届ACM省赛,简单)

    题目链接 2014年浙江省赛C题,当时觉得难,现在想想这题真水.. 找规律: 若   最大的那个步骤数*m-总和>=0,那么答案就是 最大的那个步骤数 . 否则  就要另加上不够的数量,具体看代 ...

  6. zoj 3778 Talented Chef(思维题)

    题目 题意:一个人可以在一分钟同时进行m道菜的一个步骤,共有n道菜,每道菜各有xi个步骤,求做完的最短时间. 思路:一道很水的思维题, 根本不需要去 考虑模拟过程 以及先做那道菜(比赛的时候就是这么考 ...

  7. ZOJ 3778 Talented Chef

    题目链接 题意 : 这个人需要做n道菜,每道菜Ai步,他可以同时做M道不同的菜的其中一步,问你最少需要多少时间能做完所有的菜. 思路 : 这个题比赛的时候禁锢思路了,根本没想出来,就是当M > ...

  8. ZOJ 3778 Talented Chef 模拟 [ 祝愿明天省赛一帆风顺, ZJSU_Bloom WILL WIN : )

    这题的意思是给你 n 道菜,第 i 道菜需要 Ai 步才能完成 每次你能对 m 道菜分别完成一步,请问最少需要几次? 这题暴力写肯定是不行的,去年省赛的时候就是没写出来这题,今天再把思路理一理吧. 首 ...

  9. ZOJ 3778 Talented Chief

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3778 题目 某人做菜很厉害,一分钟能同时完成最多m个菜的一道工序,输入菜的 ...

随机推荐

  1. 【转】MySQL的学习--触发器

    MySQL包含对触发器的支持.触发器是一种与表操作有关的数据库对象,当触发器所在表上出现指定事件时,将调用该对象,即表的操作事件触发表上的触发器的执行. 创建触发器 在MySQL中,创建触发器语法如下 ...

  2. token的使用流程

  3. 左右两栏div布局,高度自适应

    页面结构如下: <div class="container"> <div class="left"> left </div> ...

  4. 解决mysql的内存表“table is full”错误

    最后参考http://blog.sina.com.cn/s/blog_6942a1590101429h.html 来解决,摘录下核心 后来GOOGLE得知,需要重建该表才可以. 1. 设置新的参数 m ...

  5. cycript使用

    cycript的原理是动态库注入,但是其动态库注入的原理,与我们常见的通过LC_LOAD_DYLIB在可执行文件中注入动态库不同. cycript的操作是 : 抓取到要挂载的应用, 由于越狱机上拥有权 ...

  6. webpack使用雪碧图插件

    1.先安装插件 npm install --save-dev webpack-spritesmith 2.配置webpack 配置之前 先引入var SpritesmithPlugin = requi ...

  7. unity3d生命周期

  8. Visual Studio 2015 开发Android Cordova出现unsupported major minor version 52.0错误的解决方法

    JDK版本的问题,需要JDK1.8版本,安装!VS2015做如下设置, 工具->选项->用于Apache Cordoba的工具->环境变量替代->JAVA_HOME设为1.8:

  9. shell基础:多命令顺序执行与管道符

    有些命令的前后关系正是需要这样的关系来实现. 如在软件包的安装中: 第三个是个简单的判断:

  10. jquery.ajax请求aspx和ashx的异同 Jquery Ajax调用aspx页面方法

    1.jquery.ajax请求aspx 请求aspx的静态方法要注意一下问题: (1)aspx的后台方法必须静态,而且添加webmethod特性 (2)在ajax方法中contentType必须是“a ...