#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<queue>
using namespace std;
int main(){
    int n;
    cin>>n;
    long long int x;
    long long int s=0;
    priority_queue<long long int,vector<long long int>,greater<long long int>>q;
    for(int i=0;i<n;i++){
        cin>>x;
        s+=x;
        q.push(x);
        while(s<0){
            s-=q.top();
            q.pop();
        }
    }
    long long int ans=q.size();
    cout<<ans;
    return 0;
}