#include <bits/stdc++.h>
using namespace std;
#define ll long long

int main(){
    ll n;
    cin>>n;
    priority_queue <int, vector<int>, greater<int>> v;
    ll pos=0, neg=0,a, c=0;
    for(ll i=0;i<n;i++){
        cin>>a;
        if(a>=0){
            pos+=a;
            c++;
        }
        else{
            v.push(a);
            neg+=a;
            c++;
           /* for(auto x:v){
                cout<<x<<" ";
            }
            cout<<"\n";*/
            if(abs(neg)>pos){
                neg-=v.top();
                v.pop();
                c--;
            }
           /* cout<<"**"<<neg<<"\n\n";
             for(auto x:v){
                cout<<x<<" ";
            }
            cout<<"\n";*/
        }
    }
    cout<<c<<endl;
}
    