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. Memcached的基础梳理

    1 .Memcached 概念 官方解释如下: What is Memcached? Free & open source, high-performance, distributed mem ...

  2. 一步一步学Vue(七)

    前言:我以后在文章最后再也不说我下篇博文要写什么,之前说的大家也可以忽略,如果你不忽略,会失望的

  3. (转)sql通配符

    背景:一次搞清sql查询中的通配符问题. 1 sql通配符 通配符主要以下几种:%._.[].[^] . 在搜索数据库中的数据时,SQL 通配符可以替代一个或多个字符.SQL 通配符必须与 LIKE ...

  4. (转)java之runnable jar与普通jar

    背景:项目中有时候需要导出相关的jar包,可是总是不能分清楚. 1 导出包 导出普通jar包(可作为第三方库,类似dll,so等) 在eclipse中右键选择except->java->j ...

  5. (转)如何在maven的pom.xml中添加本地jar包

    1 maven本地仓库认识 maven本地仓库中的jar目录一般分为三层:图中的1 2 3分别如下所示: 1 groupId 2 artifactId 3 version 4 jar包的依赖 如果要将 ...

  6. 机器学习(4)Hoeffding Inequality--界定概率边界

    问题 假设空间的样本复杂度(sample complexity):随着问题规模的增长导致所需训练样本的增长称为sample complexity. 实际情况中,最有可能限制学习器成功的因素是训练数据的 ...

  7. html超级简单实现点赞(收藏)和取消赞效果

    1.前言 我们经常会遇到对一些列表呀进行点赞呀收藏数据等效果呀.今天就用html+css实现超级简单易上手的点赞和取消赞的demo展示. 2.详情 1.css样式 .like{ font-size:6 ...

  8. Hbase 基础 - shell 与 客户端

    版权说明:  本文章版权归本人及博客园共同所有,转载请标明原文出处(http://www.cnblogs.com/mikevictor07/),以下内容为个人理解,仅供参考. 一.简介 Hbase是在 ...

  9. Linux 系统下安装 rz/sz 命令及使用说明

    Linux 系统下安装 rz/sz 命令及使用说明 rz/sz命令,实现将本地的文件上传到服务器或者从服务器上下载文件到本地,但是很多Linux系统初始并没有这两个命令,以下为安装和使用的具体步骤: ...

  10. 创建Git版本库

    什么是版本库呢?版本库又名仓库,英文名repository,你可以简单理解成一个目录,这个目录里面的所有文件都可以被Git管理起来,每个文件的修改.删除,Git都能跟踪,以便任何时刻都可以追踪历史,或 ...