Description

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 <= N, M <= 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个菜,每个菜有几个步骤,煮菜的每分钟,厨师能够最多同时煮m个菜,完成选择菜的一步,(在一分钟哦)
这里求的是做菜的最短时间是多少。
我们想想如果m>n,那么他可以同时做所有菜的步骤,最短时间肯定是煮最长的那个菜的时间,如果m<n,那么我们可以这样想,厨师每分钟都同时煮m个菜,那么总的步奏需要多少次,也就是多少分钟了,那我们算出总步骤除以M,如果这个数比最多那个步骤小,就说明结果肯定是最多步骤那道菜,如果比最多那个步骤大,那就是这个数。

#include<iostream>
#include<string>
using namespace std;
int main(){
int a,n,m;
cin>>a;
while(a--){
cin>>n>>m;
int p=n;
int maxn=;
int b[];
int sum=;
for(p=n;p>;p--){
cin>>b[p];
sum=sum+b[p];
if (maxn<b[p])
{maxn =b[p];}
}
if(m>=n){cout<<maxn<<endl;}
else
{p=sum/m;
if (sum%m>)
{p=p+;}
if (p<maxn){cout<<maxn<<endl;}
else {cout<<p<<endl;} }
}
return ;
}

这里还要注意,如果不能整除呢,就还需要加一分钟,其实我不懂的就是,这里。记下吧

ZOJ3778--一道水题的更多相关文章

  1. ny525 一道水题

    一道水题时间限制:1000 ms  |  内存限制:65535 KB 难度:2描述 今天LZQ在玩一种小游戏,但是这游戏数有一点点的大,他一个人玩的累,想多拉一些人进来帮帮他,你能写一个程序帮帮他吗? ...

  2. NYOJ-525一道水题思路及详解

    一道水题 时间限制:1000 ms  |  内存限制:65535 KB 难度:2 描述 今天LZQ在玩一种小游戏,但是这游戏数有一点点的大,他一个人玩的累,想多拉一些人进来帮帮他,你能写一个程序帮帮他 ...

  3. LibreOJ #6165. 一道水题

    二次联通门 : LibreOJ #6165. 一道水题 /* LibreOJ #6165. 一道水题 欧拉线性筛 其实题意就是求区间[1, n]所有数的最小公倍数 那么答案就是所有质因子最大幂次的乘积 ...

  4. [ Luogu 4626 ] 一道水题 II

    \(\\\) \(Description\) 求一个能被\([1,n]\) 内所有数整除的最小数字,并对 \(100000007\) 取模 \(N\in [1,10^8]\) \(\\\) \(Sol ...

  5. [Luogu] P4626 一道水题 II

    ---恢复内容开始--- 题目描述 一天,szb 在上学的路上遇到了灰太狼. 灰太狼:帮我们做出这道题就放了你. szb:什么题? 灰太狼:求一个能被 [1,n] 内所有数整除的最小数字,并对 100 ...

  6. 2018焦作网络赛 - Poor God Water 一道水题的教训

    本题算是签到题,但由于赛中花费了过多的时间去滴吧格,造成了不必要的浪费以及智商掉线,所以有必要记录一下坑点 题意:方格从1到n,每一格mjl可以选择吃鱼/巧克力/鸡腿,求走到n格时满足 1.每三格不可 ...

  7. 牛客小白月赛9H论如何出一道水题(两个连续自然数互质)

    题面 记录一下...连续得两个自然数互质,这题再特判一下1的情况 #include<bits/stdc++.h> using namespace std; int main() { lon ...

  8. UPC OJ 一道水题 STL

    Problem C: 字符串游戏 Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 10  Solved: 3 [Submit][Status][Web ...

  9. 又是一道水题 hdu背包

    Problem Description 电子科大本部食堂的饭卡有一种很诡异的设计,即在购买之前判断余额.如果购买一个商品之前,卡上的剩余金额大于或等于5元,就一定可以购买成功(即使购买后卡上余额为负) ...

  10. 【我与一道水题的抗争之路】 哈理工2323 Emirp(反素数)

    题目: http://acm.hrbust.edu.cn/index.php?m=ProblemSet&a=showProblem&problem_id=2323 1,打表的姿势不对. ...

随机推荐

  1. POJ 1837 DP

    一开始看到这个题 第一反应:暴搜! 看看数据范围 ...放弃了 然后就在各种憋状态转移方程. 各种不会 还是看了Discuss里面说的才有点儿思路 直接放状态转移方程: f[i][ j+ w[i]*c ...

  2. ✡ leetcode 163. Missing Ranges 找出缺失范围 --------- java

    Given a sorted integer array where the range of elements are in the inclusive range [lower, upper], ...

  3. python 元组操作

    关于元组的常用操作,请参考:http://www.runoob.com/python/python-tuples.html 元组的元素不可修改 ,元组的元素的元素可修改 count(self,valu ...

  4. Event List 2

    The list of events can be found in src/switch_event.c in a char array called EVENT_NAMES and is summ ...

  5. docker swarm compose

    swarm docker run swarm --help compose curl -L https://github.com/docker/compose/releases/download/1. ...

  6. mac osx 快捷键符号以及意义 触发角:锁屏

    快捷键中常用符号⌘(command).⌥(option).⇧(shift).⇪(caps lock).⌃(control).↩(return).⌅(enter). OSX快捷键 快捷键中常用符号 ⌘( ...

  7. SilverlightERP&CRM源码(可用于开发基于Silverlight的CRM,OA,HR,进销存等)

    SilverlightERP系统源代码(支持创建OA.SilverlightCRM.HR.进销存.财务等系统之用) 可用于开发以下系统 SilverlightERP SilverlightCRM Si ...

  8. Asp.net MVC 之请求生命周期

    今天主要试着描述一下ASP.NET MVC 请求从开始到结束的整个生命周期,了解这些后,对MVC会有一个整体的认识. 这里主要研究了MVC请求的五个过程. 1.创建RouteTable 当ASP.NE ...

  9. Hadoop学习11--Ha集群配置启动

    理论知识: http://www.tuicool.com/articles/jameeqm 这篇文章讲的非常详细了: http://www.tuicool.com/articles/jameeqm 以 ...

  10. Install Slax on USB device (Slax U 盘安装)

    Slax is a modern, portable, small and fast Linux operating system with a modular approach and outsta ...