/// By: CooloTran
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using str = string;
#define st first
#define nd second
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define er equal_range
#define file "TEST"
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}
ll MULMOD(ll a, ll b, ll n) {
	if (b == 0) return 0;
	ll tmp = MULMOD(a, b >> 1, n);
	if (b & 1)
	return (tmp * 2 % n + a) % n;
	return tmp * 2 % n;
}
int n;
ll a[200005], cur = 0;
signed main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	// freopen(file".INP", "r", stdin);
	// freopen(file".OUT", "w", stdout);
	cin >> n;
	for (int i = 1; i <= n; ++i)
	cin >> a[i];
	priority_queue<int, vector<int>, greater<int> > pq;
	for (int i = 1; i <= n; ++i) {
		if (cur + a[i] >= 0) {
			cur += a[i];
			pq.push(a[i]);
		}
		else {
			if (pq.empty())
			continue;
			ll tmp = pq.top();
			pq.pop();
			if (tmp < a[i]) {
				pq.push(a[i]);
				cur += a[i] - tmp;
			}
			else pq.push(tmp);
		}
	}
	cout << pq.size() << '\n';
	return 0;
}