    #include <iostream>
    #include <stack>
    #include <queue>
    #include <vector>
    #include <list>
    #include <string>
    #include <algorithm>
    #include <bitset>
    #include <math.h>
    #include <iomanip>
    #include <string>
    #include <map>
        #include <set>

using namespace std;


typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi > vvi;
typedef pair<int,int> ii;
typedef vector <ii> vii;
#define REP(i,a,b)\
for (ll i=a; i<(ll)b; i++)
     
#define fastIO  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
     

/*ll toint(const string &s) { stringstream ss; ss << s; ll from; ss >> from; return from; }
string tostring ( ll number ){  stringstream ss; ss<< number; return ss.str();}*/


int main()
{
    fastIO;
    ll n;
    cin>>n;
    vi V(n);
    ll db=0;
    priority_queue <ll> negatives;
    ll possum=0;
    ll negativesum=0;
    REP(i,0,n)
    {
        cin>>V[i];
        if (V[i]>=0)
        {
            db++;
            possum+=V[i];
        }
        else
        {
            ll r=-1*V[i];
            negatives.push(r);
            negativesum+=r;
            while (negativesum>possum)
            {
                ll kd=negatives.top();
                negativesum-=kd;
                negatives.pop();
            }
        }
    }
    cout<<db+negatives.size()<<endl;
}
