#include "bits/stdc++.h"
using namespace std;
#define int long long int
int32_t main()
{
    int n;
    cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }

    priority_queue<int> q;

    int curr=0;

    int taken=0;

    for(int i=0;i<n;i++)
    {
        curr+=a[i];
        taken++;
        if(a[i]<0)
            q.push(-a[i]);
        while(curr<0)
        {
            curr+=q.top();
            q.pop();
            taken--;
        }
    }

    cout<<taken<<endl;

    return 0;
}