一开始还没想到单调 后来hint启发我这是单调的 233
#include<cstdio>
#include<cstdlib>
#include<algorithm>
using namespace std;
typedef long long ll;
inline char nc()
{
static char buf[100000],*p1=buf,*p2=buf;
if (p1==p2) { p2=(p1=buf)+fread(buf,1,100000,stdin); if (p1==p2) return EOF; }
return *p1++;
}
inline void read(int &x)
{
char c=nc(),b=1;
for (;!(c>='0' && c<='9');c=nc()) if (c=='-') b=-1;
for (x=0;c>='0' && c<='9';x=x*10+c-'0',c=nc()); x*=b;
}
inline void read(ll &x)
{
char c=nc(),b=1;
for (;!(c>='0' && c<='9');c=nc()) if (c=='-') b=-1;
for (x=0;c>='0' && c<='9';x=x*10+c-'0',c=nc()); x*=b;
}
const int N=100005;
int n,k;
ll a[N],L,R;
int check(ll x)
{
ll now=0,num=0;
for (int i=1;i<=n;i++)
{
now=max(now+a[i],0ll);
if (now>=x) num++,now=0;
}
return num;
}
int main()
{
freopen("t.in","r",stdin);
freopen("t.out","w",stdout);
read(n); read(k);
for (int i=1;i<=n;i++) read(a[i]);
ll l=1,r=1LL<<60,mid;
while (l<=r)
if (check(mid=(l+r)/2)>k)
L=mid,l=mid+1;
else
r=mid-1;
l=1,r=1LL<<60;
while (l<=r)
if (check(mid=(l+r)/2)<k)
R=mid,r=mid-1;
else
l=mid+1;
L++; R--;
if (check(L)!=k || check(R)!=k)
printf("-1\n");
else
printf("%lld %lld\n",L,R);
return 0;
}