#include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define ll long long
#define modchef (1000000007)
#define modforce 998244353

#define FAST_OP ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define pb push_back
#define mk make_pair
#define vi vector<ll>
#define pii pair<ll, ll>
#define ff first
#define ss second
#define endl "\n"
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define mem_set memset(mem, -1, sizeof mem);

// const int MAX = 2e3 + 5;
// ll mem[MAX][MAX], b[MAX];


int power(long long x, unsigned int y, int p)
{
    int res = 1; 
    x = x % p; 
    if (x == 0) return 0;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}


bool isPerfectSquare(ll int n)
{
    if(sqrt(n) == (int)sqrt(n))
        return true;
    return false;
}
 
void solve(){
    ll int n;
    cin >> n;
    ll int arr[n];
    for(int i = 0; i < n; i++){
        cin >> arr[i];
    }
    ll int sum = 0;
    priority_queue<ll int, vector<ll int>, greater<ll int> > pq;
    ll int count = 0;
    for(int i = 0; i < n; i++){
        if(arr[i] >= 0){
            sum += arr[i];
            count += 1;
        }
        else{
            if(sum + arr[i] >= 0){
                sum += arr[i];
                count += 1;
                pq.push(arr[i]);
            }
            else{
                if(!pq.empty()){
                    ll int top = pq.top();
                    if(top < arr[i]){
                        pq.pop();
                        sum -= top;
                        sum += arr[i];
                        pq.push(arr[i]);
                    }
                }
            }
        }
    }
    cout << count << endl;
}

int main(){
 
    FAST_OP;
    int t;
    t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
    return 0;
}