标签:style blog io color os for sp div on
/*
题意:给定n,m,然后n个数字,要求一个最小的lim
使得这连续n个数字可以被分为连续的m个集合,每个集合的和都不大于Lim
/*
#include <iostream> #include <cstdio> #define range(i,a,b) for (int i=a;i<=b;i++) using namespace std; const int maxn =100000; int Cost[maxn+1]; int L,R; int n,m; bool check(int val) { int sum(0); int ans(0); range(i,1,n) if (Cost[i]>val) return 0; else if (sum+Cost[i]<=val) { sum+=Cost[i]; } else { sum=Cost[i]; ans++; } if (sum!=0) ans++; return ans<=m; } int main() { cin>>n>>m; L = R = 0; range(i,1,n) { scanf("%d",&Cost[i]); R+=Cost[i]; } range(c,1,100) { int M = (L+R)>>1; if (check(M)) R=M; else L=M; } if (check(L)) cout<<L<<endl; else cout<<R<<endl; return 0; }
标签:style blog io color os for sp div on
原文地址:http://www.cnblogs.com/dandi/p/4063554.html