#include <bits/stdc++.h>
#define ll long long
#define endl "\n"
#define pb push_back
#define mp make_pair
#define ms(v,x) memset(v,x,sizeof(v))
#define td(v) v.begin(),v.end()
#define rtd(v) v.rbegin(),v.rend()
#define ff first
#define ss second
using namespace std;

std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());

const ll INF=1ll<<60;
const ll mod=1000000007;
// const ll mod=998244353;

const long double PI=acosl(-1);

ll binpow(ll a, ll b) {
	if (b == 0)
		return 1;
	ll res = binpow(a, b / 2);
	if (b % 2)
		return res * res * a;
	else
		return res * res;
}

void solve(){
	ll n,m,i,j,qt=0,sum=0;
	cin>>n;
	qt=0;
	sum=0;
	multiset<ll> res;
	for(i=0;i<n;i++){
		cin>>m;
		res.insert(m);
		sum+=m;
		qt++;
		while(sum<0){
			sum-=(*(res.begin()));
			qt--;
			res.erase(res.begin());
		}
	}
	cout<<qt<<endl;
}

int main() {
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	ll t=1;
	// cin>>t;
	// ll aux=t;
	while(t--){
		// cout<<"CASE #"<<aux-t<<": ";
		solve();
	}
}