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

#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define ld long double
#define pb push_back
#define mp make_pair
#define pl pair<int,int>
#define ff first
#define ss second
#define endl "\n"

const int N=2e5+5;
int mod=1e9+7;

void solve(){
    int n;
    cin >> n;
    return;
}

int32_t main()
{
    IOS;
    int t;
    cin >> t;
    priority_queue<int, vector<int>, greater<int>> a;
    int n,sum=0,ans=0;
    for(int i=0;i<t;i++){
        cin >> n;
        if(sum+n<0){
            while(a.size()>0 && sum+n<0 && a.top()<n){
                sum-=a.top();
                a.pop();
            }
        }
        if(sum+n>=0){
            a.push(n);
            sum+=n;
            ans=max(ans,(int)a.size());
        }
    }
    cout << ans ;
    return 0;
}