• Talented Chef ZOJ


    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 = 20000+5; int n, m, T, len, cnt, num; void input() { cin >> T; while( T -- ) { cin >> n >> m; int Max = 0; int sum = 0; for(int i=0; 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 0; }
  • 相关阅读:
    python 列表、元组、字典总结
    python 字典
    python 元组
    python 列表
    JMeter的作用域与执行顺序
    JMeter第一个实战
    JMeter录制的两种方法
    JMeter常用功能
    初识jmeter2
    handler的拒绝策略:
  • 原文地址:https://www.cnblogs.com/Asimple/p/7384080.html
Copyright © 2020-2023  润新知