1 //It is made by jump~
2 #include <iostream>
3 #include <cstdlib>
4 #include <cstring>
5 #include <cstdio>
6 #include <cmath>
7 #include <algorithm>
8 #include <ctime>
9 #include <vector>
10 #include <queue>
11 #include <map>
12 #include <set>
13 #ifdef WIN32
14 #define OT "%I64d"
15 #else
16 #define OT "%lld"
17 #endif
18 using namespace std;
19 typedef long long LL;
20 const int MAXN = 100011;
21 LL inf;
22 LL ans1,ans2;
23 int m,k;
24 LL a[MAXN];
25 LL l,r;
26
27 inline int getint()
28 {
29 int w=0,q=0;
30 char c=getchar();
31 while((c<‘0‘ || c>‘9‘) && c!=‘-‘) c=getchar();
32 if (c==‘-‘) q=1, c=getchar();
33 while (c>=‘0‘ && c<=‘9‘) w=w*10+c-‘0‘, c=getchar();
34 return q ? -w : w;
35 }
36
37 inline LL getlong()
38 {
39 LL w=0,q=0;
40 char c=getchar();
41 while((c<‘0‘ || c>‘9‘) && c!=‘-‘) c=getchar();
42 if (c==‘-‘) q=1, c=getchar();
43 while (c>=‘0‘ && c<=‘9‘) w=w*10+c-‘0‘, c=getchar();
44 return q ? -w : w;
45 }
46
47 inline LL check(LL x){
48 LL cnt=0;
49 LL now=0;
50 for(int i=1;i<=m;i++){
51 if(a[i]+now>0) now+=a[i]; else now=0;
52 if(now>=x){
53 cnt++;
54 now=0;//清零!!!
55 //if(cnt>=k) return true;
56 }
57 }
58 return cnt;
59 }
60
61 int main()
62 {
63 m=getint(); k=getint();
64 inf=1; for(int i=1;i<=60;i++) inf*=2;
65 for(int i=1;i<=m;i++) a[i]=getlong();
66 l=1,r=inf;
67 while(l<=r){
68 LL mid=(l+r)>>1;
69 if(check(mid)>k) l=mid+1,ans1=mid;
70 else r=mid-1;
71 }
72
73 l=1,r=inf;
74 while(l<=r) {
75 LL mid=(l+r)>>1;
76 if(check(mid)<k) r=mid-1,ans2=mid;
77 else l=mid+1;
78 }
79 ans1++; ans2--;
80 if(check(ans1)==k && check(ans2)==k) printf(OT" "OT,ans1,ans2);
81 else printf("-1");
82 return 0;
83 }