It means to give you n-course, I need an Ai step to finish the course.
How many times do you have to do it at least once each time you can complete one step for M-course?
This is definitely not a violent writing, the province last year when the game was not written out of the problem, today, and then the idea of a rationale.
First of all, we need to be clear
1. N <= m, then the obvious answer is Max (A[i])
2. n > M
① at this point we are not difficult to find this phenomenon, if sum (A[i]) can be divided by M, then we may just need (sum/m) times to complete
An example: n = 3, M = 2
A[1] = 1, a[2] = 2, a[3] = 3
② if sum (A[i]) cannot be divisible by M, then only 1 can be added on the basis of ①.
Of course, here should not forget, in the answer output, to ensure that the answer >= Max (A[i]), otherwise there will be a a[i] multiple subtraction operation
Paste the Source Code:
1#include <cstdio>2#include <iostream>3#include <string>4#include <cstring>5#include <stack>6#include <queue>7#include <vector>8#include <cstdlib>9#include <algorithm>Ten One using namespacestd; A - inta[60000]; - intN, M; the - intMain () { - intI, J, K, u, V, t; - +CIN >>T; - while(t--) { +CIN >> N >>m; A intsum =0; at intMAX =0; - for(i =0; I < n; ++i) { -CIN >>A[i]; -Sum + =A[i]; -MAX =Max (max, a[i]); - } in - if(N <=m) { tocout << MAX <<Endl; + Continue; - } the * intcur = SUM/m; $ if(sum% m! =0) ++cur;Panax Notoginseng -Cur =max (cur, max); the +cout << cur <<Endl; A } the + return 0; -}
ZOJ 3778 Talented Chef simulation [wish tomorrow the Provincial race sailing, Zjsu_bloom will WIN:)