abc319_d
$显然L不能设置成0$
$L满足L >= max(len_1,len_2…len_n)$
$R满足R <= sum(len_1 + 1,len_2 + 1…len_n + 1)$
int a[200005];
int n, m;
int check(int x){
int res = x;
int cnt = 1;
for(int i = 1; i <= n; ++ i){
if(res == x){
res -= a[i];
}
else{
if(res < a[i] + 1){
res = x;
++ cnt;
}
if(res == x){
res -= a[i];
}
else res -= a[i] + 1;
}
}
return cnt <= m;
}
void solve(){
n = read(), m = read();
int l = 0, r = 0;
for(int i = 1; i <= n; ++ i){
a[i] = read();
l = max(l, a[i]);
r += a[i] + 1;
}
while(l < r){
int mid = l + r >> 1;
if(check(mid)) r = mid;
else l = mid + 1;
}
cout << l;
}