谢谢各位大佬orz
#include<iostream>
#include<algorithm>
#define N 10025
using namespace std;
int m,n;
int l,r;
int a[N];
int mid;
int tim,tot;
inline bool judge(int max,int num){
for(int i=1;i<=n;i++){
if(tot+a[i]<=max) tot+=a[i];
else{
tot=a[i]; tim++;
}
}
return tim<=num;
}
int main()
{
ios::sync_with_std-io(0);
l=0;r=0;
int ans;
cin>>n>>m;
for(int i=1;i<=n;i++){
cin>>a[i];
r+=a[i]; l=max(l,a[i]);
}
while(l<=r){
mid=(l+r)>>1;
tot=0; tim=1;
if(judge(mid,m)) {
ans=mid; r=mid-1;
}
else l=mid+1;
}
cout<<mid;
return 0;
}