//Try until you reach your goal
#include <bits/stdc++.h>
using namespace std;
# define ll long long
# define endl "\n"
# define str string
# define vll vector<ll>
# define pb push_back
# define mll map<ll,ll>
# define mp make_pair
# define ff first
# define ss second
# define pll pair<ll,ll>
# define f(x,y) for(int x=0;x<y;x++)
int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    priority_queue<int,vector<int>,greater<int>>q;
    ll x;
    cin>>x;
    ll a[x];
    f(i,x){
        cin>>a[i];
    }
    ll sum=0;
    for(ll i=0;i<x;i++){
        sum=sum+a[i];
        q.push(a[i]);
        while(sum<0){
            sum-=q.top();
            q.pop();
        }
    }
    cout<<q.size();
}