#include <bits/stdc++.h>
typedef long long ll;
#define f(i,a,b) for(i=a;i<b;i++)

using namespace std;

int main()
{
    ll n,i,sum=0, count=0;
    cin>>n;
    vector<ll> a(n);
    f(i,0,n) cin>>a[i];
    priority_queue <int, vector<int>, greater<int>> p;
    f(i,0,n){
        if(a[i]>=0) sum+=a[i], count++;
        else{
            
            if(sum+a[i]>=0){
              sum+=a[i], count++; 
              p.push(a[i]);
            } 
            else{
                if(!p.empty()&&p.top()<a[i]){
                  sum-=p.top();
                  p.pop();
                  sum+=a[i];
                  p.push(a[i]);
                } 
            }
        }
    }
    cout<<count<<endl;

    return 0;
}
