二分答案,分别往尽量小的和尽量大的二分即可。
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define N 100010
#define inf 100000000000000ll
int read()
{
int x=,f=;char c=getchar();
while (c<''||c>'') {if (c=='-') f=-;c=getchar();}
while (c>=''&&c<='') x=(x<<)+(x<<)+(c^),c=getchar();
return x*f;
}
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')) c=getchar();return c;}
int gcd(int n,int m){return m==?n:gcd(m,n%m);}
int n,m,a[N];
int calc(ll k)
{
ll x=;int cnt=;
for (int i=;i<=n;i++)
{
x=max(0ll,x+a[i]);
if (x>=k) cnt++,x=;
}
return cnt;
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("bzoj4590.in","r",stdin);
freopen("bzoj4590.out","w",stdout);
const char LL[]="%I64d\n";
#else
const char LL[]="%lld\n";
#endif
n=read(),m=read();
for (int i=;i<=n;i++) a[i]=read();
ll l=,r=inf,ans=-;
while (l<=r)
{
ll mid=l+r>>;
if (calc(mid)<=m) ans=mid,r=mid-;
else l=mid+;
}
if (calc(ans)!=m) ans=-;
cout<<ans<<' ';
if (ans==-) return ;
l=,r=inf;
while (l<=r)
{
ll mid=l+r>>;
if (calc(mid)>=m) ans=mid,l=mid+;
else r=mid-;
}
cout<<ans;
return ;
}