1 #include<iostream>
2 #include<cstdio>
3 #include<cstring>
4 #include<cmath>
5 #include<algorithm>
6 #include<cstdlib>
7 #define maxn 100000+100
8 int a[maxn],n,m,ans;
9 bool pan(int q)
10 {
11 int sum=0,tot=1; //切记tot=1;
12 for(int i=1;i<=n;++i)
13 {
14 if(sum+a[i]<=q) sum+=a[i];
15 else
16 {
17 sum=a[i];++tot;
18 }
19 if(tot>m||a[i]>q) return 0;
20 }
21 return 1;
22 }
23 int erfen(int p)
24 {
25 int l=1,r=100000000;
26 while(l<=r)
27 {
28 int mid=(l+r)>>1;
29 if(pan(mid)) {
30 ans=mid;r=mid-1;
31 }
32 else l=mid+1;
33 }
34 return ans;
35 }
36 using namespace std;
37 int main()
38 {
39 freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
40 cin>>n>>m;
41 for(int i=1;i<=n;++i) scanf("%d",&a[i]);
42 erfen(n);
43 cout<<ans;
44 return 0;
45 }