1 #include<cstdio>
2 #include<iostream>
3 #define maxn 1000000
4 using namespace std;
5
6 int n,m,arr[maxn],sum,maxx;
7
8 bool check(int x){
9 int cnt = 0,tmp = 0;
10 for(int i = 1;i <= n;i++){
11 if(cnt + arr[i] > x)
12 tmp++,cnt = 0;
13 cnt += arr[i];
14 }tmp++;
15 if(tmp > m) return false;
16 else return true;
17 }
18
19 int main(){
20 scanf("%d%d",&n,&m);
21
22 for(int i = 1;i <= n;i++){
23 scanf("%d",&arr[i]);
24 maxx = max(maxx,arr[i]);
25 sum += arr[i];
26 }
27
28 int l = maxx,r = sum,mid;
29 while(l < r){
30 mid = (l+r)/2;
31 if(check(mid)) r = mid;
32 else l = mid+1;
33 }
34
35 printf("%d",l);
36
37 return 0;
38 }