| Time Limit: 2000MS | Memory Limit: 65536K | |
| Total Submissions: 14719 | Accepted: 5895 |
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 next N (1 ≤ N ≤ 100,000) days.
FJ wants to create a budget for a sequential set of exactly M (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
Lines 2.. N+1: Line i+1 contains the number of dollars Farmer John spends on the ith day
Output
Sample Input
7 5 100 400 300 100 500 101 400
Sample Output
500
Hint
Source
代码很清楚,相信很容易就懂了。
AC代码:
#include<iostream>
using namespace std;
int a[100010];
int main(){
int n,m;
int low,high;
while(cin>>n>>m){
low=0; high=0;
for(int i=0;i<n;i++){
cin>>a[i];
high+=a[i];
if(a[i]>low)
low=a[i];
}
while(low<high){
int mid=(low+high)/2;
int s,t;
s=t=0;
for(int i=0;i<n;i++){
if(s+a[i]<=mid){
s+=a[i];
}
else{
s=a[i];
t++;
}
}
if(t<=m)
high=mid-1;
else
low=mid+1;
}
cout<<low<<endl;
}
return 0;
}
最小化月度支出预算

Farmer John 使用会计技巧管理农场财务,通过合理安排连续天数的支出,以确定最经济的月度预算上限。
373

被折叠的 条评论
为什么被折叠?



