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. Java通过POI生成Excel

    import java.io.FileOutputStream; import java.text.SimpleDateFormat; import java.util.ArrayList; impo ...

  2. VS Code的golang开发配置 之 代码提示

    之前用VS Code的时候,发现自己的代码的提示一直不好,换用JetBrain的Goland的代码提示是好了,但是比较占用资源.在网上找了一些资料,发现很多人也是遇到第三方或者自己的代码无法提示的情况 ...

  3. vue--项目文件

    build config:webpack的配置文件 node_modules: 依赖的npm包 src: 项目代码 static:依赖的第三方库 ps:static中有个文件.gitkeep 因为新建 ...

  4. theos第一次编译成功,记录一下

    theos 是github 90444af分支上的,下载设置环境变量 vi /etc/profile. 将/opt/theos/bin加入环境变量 运行nic.pl f 输入11生成工程,一路跳过 最 ...

  5. HDU 2842 Chinese Rings(常数矩阵)

    Chinese Rings 转载自:点这里 [题目链接]Chinese Rings [题目类型]常数矩阵 &题意: 一种中国环,解开第k个环需要先解开全部的前(k-2)个环,并留有第(k-1) ...

  6. Xshell连接不上虚拟机提示ssh服务器拒绝了密码,请再试一次

    1. 设置ubuntu的管理员root的密码 hughes@hughes-virtual:~$ sudo passwd (供xshell连接时使用) 2. 确保源文件和系统已更新 hughes@hug ...

  7. html常用文本标签(转)

    内容一<br />内容二 让文本强制换行 内容一内容二 <p>段落一</p><p>段落二</p> 段落标签 段落一 段落二 <b> ...

  8. caffe训练脚本文件时遇到./build/tools/caffe: not found

    原文转载:https://blog.csdn.net/zhongshaoyy/article/details/53502373 cifar10训练步骤如下: (1)打开终端,应用cd切换路径,如 cd ...

  9. WIN32窗口类风格和窗口风格(备查询)

    一.WNDCLASS typedef struct { UINT cbSize //这个结构体的长度,一般用sizeof(WNDCLASSEX)设置 UINT style //窗口式样 WNDPROC ...

  10. sitecore系统教程之架构概述

    Sitecore体验数据库(xDB)从实时大数据存储库中的所有通道源收集所有客户交互.它连接交互数据,为每个客户创建全面,统一的视图,并使营销人员可以使用数据来管理客户的实时体验. xDB架构非常灵活 ...