显然n递增的时候k会递减
于是可以二分n的值,检查一下与k的大小关系
(不要问我怎么证,感觉就是这样的)
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<queue>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<stack>
#include<cstdlib>
#include<ctime>
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define per(i,r,l) for(int i=r;i>=l;i--)
#define mmt(a,v) memset(a,v,sizeof(a))
#define tra(i,u) for(int i=head[u];i;i=e[i].next)
using namespace std;
typedef long long ll;
const ll inf=1LL<<60;
const int N=100000+5;
int n,m,x[N];
int calc(ll k){
int cnt=0;
ll now=0;
rep(i,1,n){
now=max((ll)0,now+x[i]);
if(now>=k)now=0,cnt++;
}
return cnt;
}
int main(){
//freopen("a.in","r",stdin);
scanf("%d%d",&n,&m);
rep(i,1,n)scanf("%d",&x[i]);
ll l=1,r=inf;
while(l<=r){
ll mid=l+r>>1;
if(calc(mid)<=m)r=mid-1;
else l=mid+1;
}
if(calc(r+1)!=m){puts("-1");return 0;}
printf("%lld ",r+1);
l=0,r=inf;
while(l<=r){
ll mid=l+r>>1;
if(calc(mid)>=m)l=mid+1;
else r=mid-1;
}
printf("%lld\n",l-1);
return 0;
}