只AC了#4
#include<cstdio>
int n,m,maxa,suma,a[100010];
inline int max(int x,int y){
return x>y?x:y;
}
bool check(int x){
int sum=0,cnt=0;
for(int i=1;i<=n;i++){
if(sum+a[i]>x)
cnt++,sum=a[i];
else sum+=a[i];
}return cnt<=m;
}
int Find(){
int l=maxa,r=suma;
while(l<=r){
int mid=l+r>>1;
if(check(mid))r=mid-1;
else l=mid+1;
}
return l;
}
int main(){
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++){
scanf("%d",&a[i]);
maxa=max(maxa,a[i]);
suma+=a[i];
}
printf("%d",Find());
return 0;
}