1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const int MAXN = 5e5+4;
ll pref[MAXN];

ll query(int l, int r)
{
	return pref[r] - pref[l-1];
}

int main()
{
	ios_base::sync_with_stdio(false);
	int n; cin >> n;
	for(int i = 1; i <= n; i++)
		cin >> pref[i], pref[i] += pref[i-1];
	int l = 1, ans = n-1;
	for(int i = 1; i < n; i++)
		if(query(l,i) >= 0 && query(i+1,n) >= 0) l = i+1, ans--;
	cout << ans;
	return 0;
}