标签:poj
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 16813 | Accepted: 6666 |
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
Output
Sample Input
7 5 100 400 300 100 500 101 400
Sample Output
500
Hint
/* 二分求下限 */ #include <stdio.h> #include <string.h> const int maxn=100000+10; int n,m; int a[maxn]; bool C(int x){ int i,cnt=1,sum=0; for(i=0;i<n;i++){ if(a[i]>x) return false; sum+=a[i]; if(sum>x){ //如果>x了,这个月就可以停,并且i这一天要算到下个月里 sum=a[i]; cnt++; } } return cnt<=m; } int main() { int i,max; while(scanf("%d%d",&n,&m)!=EOF){ for(i=0;i<n;i++) scanf("%d",&a[i]); int l=-1,r=1000000000; while(r-l>1){ int M=(l+r)/2; if(C(M)) r=M; else l=M; } printf("%d\n",r); } return 0; }
标签:poj
原文地址:http://blog.csdn.net/u013068502/article/details/45765849