[ZOJ 3778] Talented Chef

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5265

想多了
如果m >= n,肯定时n个dish中用时最多的
如果m < n,计算一下平均用时,即ave = sum / m,注意除不尽加1,然后和这n个dish中最大的值比较,如果ave小于最大的,那么用时为最大的,否则为ave。

AC代码:

#include <cstdio>

using namespace std;

int test;
int n, m;
int x;
long long sum;
long long maxn;

int main() {
    scanf("%d", &test);
    while (test--) {
        sum = 0;
        maxn = -1;
        scanf("%d%d", &n, &m);
        for (int i = 0; i < n; i++) {
            scanf("%d", &x);
            sum += x;
            if (maxn < x) {
                maxn = x;
            }
        }
        if (n <= m) {
            printf("%lld\n", maxn);
        } else {
            long long ave = sum / m;
            if (sum % m) {
                ave += 1;
            }
            if (ave < maxn) {
                printf("%lld\n", maxn);
            } else {
                printf("%lld\n", ave);
            }
        }
    }
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/youpeng/p/10799568.html
ZOJ