1 #include<cstdio>
2 #include<cstdlib>
3 #include<cmath>
4 #include<cstring>
5 #include<algorithm>
6 #include<iostream>
7 #include<vector>
8 #include<map>
9 #include<set>
10 #include<queue>
11 #include<string>
12 #define inf 1000000000
13 #define maxn 100000+100
14 #define maxm 500+100
15 #define eps 1e-10
16 #define ll long long
17 #define pa pair<int,int>
18 using namespace std;
19 inline int read()
20 {
21 int x=0,f=1;char ch=getchar();
22 while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();}
23 while(ch>=‘0‘&&ch<=‘9‘){x=10*x+ch-‘0‘;ch=getchar();}
24 return x*f;
25 }
26 int n,m,a[maxn];
27 bool check(int x)
28 {
29 int cnt=0,sum=0;
30 for(int i=1;i<=n;i++)
31 {
32 sum+=a[i];
33 if(sum>x)sum=a[i],cnt++;
34 if(sum>x)return 0;
35 }
36 return cnt+1<=m;
37 }
38 int main()
39 {
40 freopen("input.txt","r",stdin);
41 freopen("output.txt","w",stdout);
42 n=read();m=read();
43 for(int i=1;i<=n;i++)a[i]=read();
44 int l=0,r=inf,mid;
45 while(l<=r)
46 {
47 mid=(l+r)>>1;
48 if(check(mid))r=mid-1;else l=mid+1;
49 }
50 printf("%d\n",l);
51 return 0;
52 }