二分答案水题。
#include#include #include #include using namespace std;#define maxn 100005#define ll long longll n,k,a[maxn],minn,maxx;#define llinf 10000000000000000LL#define F(i,j,k) for (ll i=j;i<=k;++i)ll check(ll lim){ ll now=0,ret=0; F(i,1,n) { now+=a[i]; if (now<0) now=0; if (now>=lim) now=0,ret++; } return ret;} int main(){ scanf("%lld%lld",&n,&k); F(i,1,n) scanf("%lld",&a[i]); ll l=1,r=llinf; while(l =k) l=mid; else r=mid-1; } maxx=l; if (check(minn)!=k&&check(maxx)!=k) printf("-1\n"); else printf("%lld %lld\n",minn,maxx);}