#include <iostream> #include <cstdio> using namespace std; long long n,m,a[100005]; long long check(long long mid) { long long total=0; long long s=0; for (int i=1;i<=n;) { while (s+a[i]<=mid&&i<=n) s+=a[i++]; total++;s=0; } return total; } int main() { long long left=0,right; long long sum=0; //freopen("in.txt","r",stdin); cin>>n>>m; for (int i=1;i<=n;i++) { cin>>a[i]; sum+=a[i]; if (a[i]>left) left=a[i]; } right=sum; while (right-left>1) { long long mid; mid=(left+right)/2; // cout<<left<<" "<<mid<<" "<<right<<" "<<check(mid)<<endl; if (check(mid)<=m) right=mid;else left=mid; } if (check(left)<=m) cout<<left;else cout<<right; return 0; } 题意:给定一个数列,要求把数列切分成m个段,使得总和最大的一段的总和最小。求这个总和。