CF F. ATM and Students (双指针)(1800)
https://codeforces.com/contest/1611/problem/F
负了就停止,这使得问题有了单调性,使用双指针
双指针模版
//初始为空
int l = 1, r = 0; ll sum = 0;
for ( ; l <= n; ++ l ) {
r = max(l - 1, r); //下一步满足条件r再走上去 ,保证[l, r]是合法区间
while( r < n && sum + a[r + 1] >= 0 ) sum += a[++ r];
if(r - l + 1 > R - L + 1) R = r, L =l; //更新答案,这个是最值的区间
if( l <= r ) sum -= a[l]; //l往前走,若r<l本来就为空,不要再减
}