1639: [Usaco2007 mar]monthly Expense monthly expenditure time limit:5 Sec Memory limit:64 MB
submit:593 solved:295
[Submit] [Status] Description
Farmer John was a surprising accounting genius who had understood that he might spend his money, which was supposed to keep the farm running every month. He has calculated the cost of moneyi (1<=moneyi<=10,000) for each day of his next N (1<=n<=100,000) business day, and he wants to be a serial M (1<=m<=n) called "Liquidation Month" for him. Checkout period to make a budget, each "Liquidation month" contains one business day or more consecutive working days, each working day is only included in a "liquidation month". FJ's goal is to arrange these "clearing months" to minimize the cost of each liquidation month, thus determining his monthly spending limit.
Input
First line: Two integers separated by a space: N and M
2nd.. N+1 Line: Line i+1 contains the cost of FJ on his first business day
Output
The first line: The amount of money that keeps the farm running every month.
Sample Input7 5
100
400
300
100
500
101
400
Sample Output500
Enter details
There are 7 business days to be divided by 5 "clearing months". He spends 100,400,100,500,101, and 400 dollars in his every weekday.
Output details
If FJ arranges his monthly budget, he will divide the first two days into one months, dividing the third and fourth days into one months, and the last three working days in one months, so he spends one months at most, and other methods always come up with a bigger result.
100 400 300 100 500 101 400 cost per day
---1------2----3----monthly marking
500 400 500 101 400 monthly cost
HINT Source
Silver
Problem: Pit Pit Pit--the title is written according to the order of the topic to divide the "liquidation month", but I still very funny than the line of the order, and then wa ... This question to say also has nothing to say, is a classic two-point answer question (the solution has the monotony of the topic can), first determine the upper and lower limit of an answer, and then start the two points + to determine whether it is feasible, then no then ...
1 var2 I,j,k,l,m,n,x,y,t:longint;3A:Array[0..100000] ofLongint;4 proceduresort (l,r:longint);5 var6 I,j,x,y:longint;7 begin8i:=l;j:=R;9x:=a[(L+r)Div 2];Ten Repeat One whileA[i]<x DoInc (i); A whileA[j]>x DoDec (j); - ifI<=j Then - begin they:=A[i]; -a[i]:=A[j]; -a[j]:=y; - Inc (I);d EC (j); + End; - untilI>J; + ifI<r Thensort (i,r); A ifL<j Thensort (l,j); at End; - functionCheck (X:longint): boolean; - var - I,j,k,l:longint; - begin -l:=0; k:=0; in fori:=1 toN Do - begin tol:=l+A[i]; + ifL>x Then - begin the Inc (k); *l:=A[i]; $ End;Panax Notoginseng ifL>x Thenexit (false); - End; theExit (k<m); + End; A begin the readln (n,m); + fori:=1 toN Doreadln (A[i]); -Sort1, n); $x:=a[n];y:=0; $ forI:=nDowntoM Doy:=y+A[i]; - whileX<y Do - begin thet:= (X+y)Div 2; - ifCheck (t) ThenWuyiy:=T the Else -x:=t+1; Wu End; - writeln (x); About End. $
1639: [Usaco2007 mar]monthly Expense monthly expenditure