#include <bits/stdc++.h>
#define pb push_back
using namespace std;
#define F first
#define sz size()
#define S second
#define in insert
#define lb lower_bound
#define int long long
#define all(v) v.begin(), v.end()
#define FOR(x, n, m, d) for(int x = n; x <= m; x += d)
#define FORR(x, n, m, d) for(int x = n; x >= m; x -= d)
#define nikita ios_base::sync_with_stdio(0), cin.tie(0);
const int N = 5e5+5;
int n,m,tt,sum=0,l, r, x, y, cnt[N], block = 448, res;
int a[N], b[N], c[N], ans, pref[N], t[N*6], inf = 1e18+7, mn = 1e18;
void upd(int pos, int val, int v = 1, int tl = 1, int tr = n){
if(tl == tr){
t[v] = val;
return;
}
int tm = (tl + tr) >> 1;
if(pos <= tm)upd(pos, val, v*2, tl, tm);
else upd(pos, val, v*2+1, tm+1, tr);
t[v] = min(t[v*2], t[v*2+1]);
}
int get(int val, int v = 1, int tl = 1, int tr = n){
if(tl==tr)return tl;
int tm = ( tl + tr ) >> 1;
if(t[v*2+1] <= val)return get(val, v*2+1, tm+1, tr);
return get(val, v*2, tl, tm);
}
void solve() {
cin >> n;
fill(t, t+N*6, inf);
set<pair<int, int>>st;
FOR(i,1,n,1){
cin >> a[i];
pref[i] = pref[i-1] + a[i];
}
cnt[1] = 1;
ans = 1;
FOR(i, 1, n, 1){
int last = 0;
if(mn <= pref[i])last = get(pref[i]), cnt[i] = cnt[last] + 1;
else cnt[i] = 1;
ans = max(ans, cnt[i]);
upd(i, pref[i]*2 - pref[last]);
mn = min(mn, pref[i]*2 - pref[last]);
}
cout << ans;
}
signed main()
{
nikita
tt = 1;
if(!tt)cin >> tt;
FOR(i, 1, tt, 1){
solve();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |