zoukankan      html  css  js  c++  java
  • 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; }
  • 相关阅读:
    MS SQL数据类型
    ASP中调用存储过程、语法、写法-sql server数据库
    系統存儲過程System stored procedures
    ASP调用带参数存储过程的几种方式
    解密SQLSERVER2000存储过程,函数,视图,触发器
    SQL Script 執行的時間
    各種正則表达式示例
    12款操作系统安装全程图解(菜鸟必备宝典)
    内存 : DDR2与DDR
    數據庫分頁
  • 原文地址:https://www.cnblogs.com/Asimple/p/7384080.html
Copyright © 2011-2022 走看看