标签:
#include<cstdio> using namespace std; #define N 100001 int n,m,a[N]; bool check(int x) { int now=0,sum=1; for(int i=1;i<=n;++i) { if(now+a[i]<=x) now+=a[i]; else { now=a[i]; ++sum; if(now>x||sum>m) return 0; } } return 1; } int main() { scanf("%d%d",&n,&m); for(int i=1;i<=n;++i) scanf("%d",&a[i]); int l=1,r=1000000000; while(r>l) { int mid=(l+r>>1); if(check(mid)) r=mid; else l=mid+1; } printf("%d\n",l); return 0; }
【二分答案】bzoj1639 [Usaco2007 Mar]Monthly Expense 月度开支
标签:
原文地址:http://www.cnblogs.com/autsky-jadek/p/4441012.html