//  ---Author: Đặng Võ Hồng Phúc---  //
#include<bits/stdc++.h>
#define name "1526C1"
#define maxn 200005
#define oo LLONG_MAX
#define fo(i,a,b) for(ll i=a;i<=b;++i)
#define CONST
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long ll;
template<class T> void MIN(T &A, T B) {A=min(A,B);}
template<class T> void MAX(T &A, T B) {A=max(A,B);}
template<class T> void SUM(T &A, T B) {A=A+B;}
template<class T> void HIEU(T &A, T B) {A=A-B;}
ll n,a[maxn],sum[maxn];
bool check[maxn];
void solve()
{
    priority_queue<ll,vector<ll>,greater<ll>>q;
    ll tmp=0,ans=0;
    fo(i,1,n)
    {
        tmp+=a[i],++ans,q.push(a[i]);
        while(tmp<0) tmp-=q.top(),--ans,q.pop();
    }
    cout<<ans;  

}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);  cout.tie(0);
//    freopen(name".inp","r",stdin);
//    freopen(name".out","w",stdout);
    cin>>n;
    fo(i,1,n) cin>>a[i];
    solve();
}
