1、题意:题意很简洁吧,就不概括了
2、分析:我思考了半天,我猜答案满足单调。。。没敢写,看了题解去问Claris为啥单调,Claris一句话“ 因为n越大明显不可能做更多题 ”,后来没找到反例我也放弃了
满足单调的话就二分答案咯
#include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> using namespace std; #define M 200010 #define LL long long inline int read(){ char ch = getchar(); int x = 0, f = 1; while(ch < '0' || ch > '9'){ if(ch == '-') f = -1; ch = getchar(); } while('0' <= ch && ch <= '9'){ x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } int a[M]; int n, m; inline int check(LL x){ int cnt = 0; LL now = 0; for(int i = 1; i <= n; i ++){ now += a[i]; now = max(0ll, now); if(now >= x) cnt ++, now = 0; } return cnt; } int main(){ n = read(), m = read(); for(int i = 1; i <= n; i ++) a[i] = read(); LL l = 1, r = 10000000000000, t1 = 1, t2 = 10000000000000; while(l <= r){ LL mid = (l + r) / 2; if(check(mid) >= m) l = (t1 = mid) + 1; else r = mid - 1; } l = 1, r = 10000000000000; while(l <= r){ LL mid = (l + r) / 2; if(check(mid) <= m) r = (t2 = mid) - 1; else l = mid + 1; } if(check(t2) != m || check(t1) != m){ printf("-1"); return 0; } printf("%lld %lld", t2, t1); return 0; }