| Time Limit: 2000MS | Memory Limit: 65536K | |
| Total Submissions: 5544 | Accepted: 2253 |
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
#include<cstdio>
using namespace std;
int a[110000];
int ok(int goal,int n,int m)//是否能 将n分为连续的m份,其和最大不超过goal
{
int s=0,cnt=1;
for(int i=0;i<n;i++)
{
if(a[i]>goal||s>goal) return 0;
if(s+a[i]<=goal) s+=a[i];
else
{
s=a[i];cnt++;
}
}
if(cnt<=m) return 1;
return 0;
}
int main()
{
int n,m;
while(scanf("%d%d",&n,&m)==2)
{
int _min=-(1<<30),_max=0;
for(int i=0;i<n;i++)
{
scanf("%d",&a[i]);
_max+=a[i];_min=_min>a[i]?_min:a[i];
}
int low=_min,high=_max;
while(low<high)
{
int mid=(low+high)>>1;
if(ok(mid,n,m)) high=mid;
else low=mid+1;
}
printf("%d/n",low);
}
return 0;
}
预算规划挑战
本文介绍了一个预算规划问题,农民约翰需要将未来的支出分配到若干个连续的周期中,以确保每个周期的最大开销最小化。通过一种特殊的预算划分方法,文章提供了一种有效的解决方案。
3264

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



