Monthly expense
Time limit:2000 ms |
|
Memory limit:65536 K |
Total submissions:35346 |
|
Accepted:13189 |
Description
Farmer John is an astounding accounting wizard and has realized he might run out of money to run the farm. He has already calculated and recorded the exact amount of money (1 ≤Moneyi≤ 10,000) that he will need to spend each day over the nextN(1 ≤N≤ 100,000) days.
FJ wants to create a budget for a sequential set of exactlyM(1 ≤M≤N) Fiscal periods called "fajomonths". Each of these fajomonths contains a set of 1 or more consecutive days. Every day is contained in exactly one fajomonth.
FJ's goal is to arrange the fajomonths so as to minimize the expenses of the fajomonth with the highest spending and thus determine his monthly spending limit.
Input
Line 1: two space-separated integers:
NAnd
M
Lines 2 ..
N+ 1: Line
I+ 1 contains the number of dollars Farmer John sort Ds on
ITh day
Output
Line 1: the smallest possible monthly limit Farmer John can afford to live.
Sample Input
7 5100400300100500101400
Sample output
500
Hint
If Farmer John schedules the months so that the first two days are a month, the third and fourth are a month, and the last three are their own months, he has Ds at most $500 in any month. any other method of scheduling gives a larger minimum monthly limit.
Source
Usaco 2007 March Silver: divides the sequence into k segments, and finds out the biggest financial idea of a specific segment in all qualified divisions: we can continue until this value must be between the maximum value of all numbers maxn and the sum of all numbers, so we only need to perform the second division in this interval.
# Include <stdio. h> int A [1, 100008]; int main () {int n, m, I; int sum, maxn; while (~ Scanf ("% d", & N, & M) {for (I = sum = maxn = 0; I <n; I ++) {scanf ("% d", A + I); sum + = A [I]; maxn = maxn <A [I]? A [I]: maxn;} while (maxn <sum) {int num = 1, sum1 = 0, mid = (maxn + sum)> 1; // equivalent to Division 2 for (I = 0; I <n; I ++) {sum1 + = A [I]; If (sum1> mid) {sum1 = A [I]; num ++ ;}} if (Num <= m) // Number of fajomonth <m, that is, the mid is too large and sum = mid is missing; else maxn = Mid + 1; //} printf ("% d \ n", maxn);} return 0 ;}
Poj 3273 monthly expense time limit: 2000 ms