#include<bits/stdc++.h>
#include<sstream>
using namespace std;
const int INF = 1e9;
const int N = 300007;
const int mod = 1e9 + 7;
const double eps = 1e-6;
#define pa pair<int, int>
#define ll long long
#define rep(i, a, b) for(int i=(a);i<=(b);++i)
#define per(i, a, b) for(int i=(a);i>=(b);--i)
#define ms(a, b) memset(a, b, sizeof a)
int T, n;
void solve() {
	cin >> n;
    priority_queue<ll, vector<ll>, greater<ll>>q;
    ll s = 0;
    for (int i = 1; i <= n; ++i) {
        ll x; 
		cin >> x;
        s += x;
        q.push(x);
        while (s < 0) {
            s -= q.top();
            q.pop();
        }
    }
    cout << q.size();
}
int main()
{
	solve();
}