#include <bits/stdc++.h>
using namespace std;
typedef long long                                    ll;
typedef vector<int>                                  vi;
typedef vector<int, int>                             vii;
typedef pair<int, int>                               pii;
#define rep(i,a,b)                                   for(int i = a; i <= b; i++)
#define rrep(i,a,b)                                  for(int i = a; i >= b; i--)
#define trav(it,v)                                   for(auto it = v.begin(); it!= v.end(); it++)
#define pb                                           push_back
#define popb                                         pop_back  
#define sz(x)                                        x.size()
#define fr                                           first
#define sc                                           second

const int M = 1e9+7;
const ll INF = 1e18;

void solve(int t){
    int n;
    cin >> n;
    int a[n];
    rep(i,0,n-1){
        cin >> a[i];
    }
    priority_queue<int> q;
    ll sum = 0;
    int cnt = 0;
    rep(i,0,n-1){
        if(sum+a[i]>=0){
            cnt++;
            sum += a[i];
            if(a[i]<0){
                q.push(-a[i]);
            }
        }
        else if(!q.empty() && -q.top()<a[i]){
            sum -= -q.top();
            q.pop();
            sum += a[i];
            q.push(-a[i]);
        }
    }
    cout << cnt;
    return;
}


int main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 

    // #ifndef LOCALFLAG 
	// 	freopen("input.txt", "r", stdin);
	// 	freopen("output.txt", "w", stdout);
	// #endif

    int t = 1;
    // cin >> t;
    rep(i,1,t){
        solve(i);
    }
    return 0;
}