#include<bits/stdc++.h>
#define ll long long
using namespace std;
#define pb push_back
#define pop pop_back
#define mp make_pair
#define mod 1000000007
#define PI 3.141592653589793238462
#define endl "\n"


#ifndef ONLINE_JUDGE
#define debug(x) cerr << #x <<" "; _print(x); cerr << endl;
#else
#define debug(x)
#endif
int main()
{ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t=1;
 //cin>>t;
 while(t--){
 ll n,i;
 cin>>n;
vector<ll>a(n);
 for(i=0;i<n;i++){
    cin>>a[i];
 }
multiset<ll>m;
ll s=0;
for(i=0;i<n;i++){
    m.insert(a[i]);
    s=s+a[i];
    if(s<0){
      s=s-(*m.begin());
        m.erase(m.begin());

    }
}
cout<<m.size()<<endl;
}
return 0;
}
//n & (1<<i)- for extracting ith bits
//while(n>0){count=count+(n&1); n=n>>1;}//counting set bits




