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 M different 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 T indicating 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

题目大意:给出n(表示有n道菜)、m(表示能同时煮m道菜),给出每道菜的时间,求最少需要煮多久。

思路:直接比较时间最长那道菜和总时间除以m的值哪个最大,取最大的即可。因为要嘛就是煮完的时候要嘛就是时间最长那道菜的时间,要嘛就是总时间除以m。

代码如下

 /*
* Author: Joshua
* Created Time: 2014/5/18 13:30:03
* File Name: c.cpp
*/
#include<cstdio> void solve()
{
int n,m,max=,ans,sum=;
int a[];
scanf("%d%d",&n,&m);
for (int i=;i<=n;i++)
{
scanf("%d",&a[i]);
if (a[i]>max) max=a[i];
sum+=a[i];
}
if ((sum-)/m+ >max) printf("%d\n",(sum-)/m+);
else printf("%d\n",max);
} int main()
{
int times;
scanf("%d",&times);
while (times)
{
times--;
solve();
}
return ;
}

zoj3778 Talented Chef的更多相关文章

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

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

  2. Talented Chef ZOJ - 3778

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

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

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

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

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

  5. zoj 3778 Talented Chef(思维题)

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

  6. ZOJ 3778 Talented Chef

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

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

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

  8. ZOJ 3778 C - Talented Chef 水题

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

  9. ZOJ3778--一道水题

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

随机推荐

  1. 【Splay】例题

    营业额统计 题目背景 HNOI2002 DAY2 T2 题目描述 Tiger 最近被公司升任为营业部经理,他上任后接受公司交给的第一项任务便是统计并分析公司成立以来的营业情况. Tiger 拿出了公司 ...

  2. JavaScript Base64加解密

    Base64加密算法是网络上最常见的用于传输8Bit字节代码的编码方式之一,大家可以查看RFC2045-RFC2049,上面有MIME的详细规范.Base64编码可用于在HTTP环境下传递较长的标识信 ...

  3. aspcms多图调用以及错误提示:3704

    1.“为师资介绍”(相册列表)建立了内容页(相册内容页), 需要对模板页面改造,在相册详细页调用多图,之前没有试过,这次利用: 实现多图调用,注意不能使用contentid=[content:id]  ...

  4. 任务调度---crontab

    1.   crontab相当于windows下的任务与计划,可以设定定时任务,周期执行的任务 2.   设置任务调度文件 crontab  -e       进入任务界面,添加如下命令 0 2 * * ...

  5. sping 框架学习之——初始篇

    sping框架学习: 1,什么是spring框架 spring是J2EE应用程序框架,是轻量级的IoC和AOP的容器框架,主要是针对javaBean的生命周期进行管理的轻量级容器,可以单独使用,也可以 ...

  6. ORACLE - 系统参数调整

    一.内存调整 oracle 11g中,ORACLE把SGA与PGA统一管理,总和为memory_target参数的设定,也就是MAX(SGA+PGA)<= memory_target(当然可以在 ...

  7. swift3.0 对UITextField()输入框输入的内容进行监控

    首先需要继承 UITextFieldDelegate class TestViewController: UIViewController,UITextFieldDelegate{ } 添加事件委托 ...

  8. IntelliJ IDEA(2017.2)安装和破解(转)

    如果有一定的经济基础,请支持正版,这里提供破解方法. 一.下载并安装, IntelliJ IDEA的官网:https://www.jetbrains.com 二.破解. 百度下载一个 Jetbrain ...

  9. akoj-1059-Picture

    Description 给你一个矩形的宽度和高度,要求按sample output样例输出此矩形. Input 输入包含多组数据,每一组包含两个数N和M( 0 < N ,M , < 75 ...

  10. <Mastering KVM Virtualization>:第三章 搭建独立的KVM虚拟化

    在第二章,你了解了KVM的内部结构:在本章中,您将了解如何将Linux服务器设置为虚拟化主机.我们正在讨论将KVM用于虚拟化并将libvirt作为虚拟化管理引擎. KVM开启了虚拟化并利用你的服务器或 ...