#include<bits/stdc++.h>
#define ll long long
#define db double
#define fi first
#define se second
using namespace std;
priority_queue <ll,vector<ll>,greater<ll> > Q;
ll n,ans;
int main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        ll t;
        scanf("%lld",&t);
        ans+=t;
        Q.push(t);
        while(ans<0){
            ans-=Q.top();
            Q.pop();
        }
    }
    cout<<Q.size()<<endl;
}