#include<bits/stdc++.h>

using namespace std;

#define ll long long
priority_queue<ll,vector<ll>,greater<ll> >tt;
ll all[200005];
int main()
{
	ll N,now=0,ans=0,i;
	scanf("%lld",&N);
	for(i=0;i<N;i++){
		scanf("%lld",&all[i]);
		if(all[i]>=0){
			ans++;now+=all[i];
		}
		else if(now+all[i]>=0){
			ans++;now+=all[i];
			tt.push(all[i]);
		}
		else if(!tt.empty()&&all[i]>tt.top()){
			now-=tt.top();
			now+=all[i];
			tt.pop();
			tt.push(all[i]);
		}
	}
	cout<<ans<<endl;
}
