#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define  boost ios_base::sync_with_stdio(false);cin.tie(NULL);
int main(){
	boost;
    ll n;
    cin>>n;
    ll arr[n];
    vector<pair<long long ,long long > > vec;
    priority_queue<ll,vector<ll>, greater<ll> > pq;
    ll cnt = 0;
    for(ll i=0;i<n;i++){
    	cin>>arr[i];
    	if(arr[i] >= 0){
    		vec.pb(mp(arr[i],i));
		}
		else{
			cnt++;
		}
	}
	if(cnt == n){
		cout<<vec.size()<<endl;
		
	}else{
	
	ll answ = 0;
    ll lasti = n-1;
	for(ll i=(vec.size()-1);i>=0;i--){
	   ll val = vec[i].first;
	   ll index = vec[i].second;
	   for(ll j=lasti;j>=index;j--){
	   	if(arr[j]<0){
	   		pq.push((abs(arr[j])));
		   }
	   }
	   lasti = index;
	   answ++;
	   while((!pq.empty())&&(val > 0)){
	   	ll vl = pq.top();
	   	if(vl <= val){
	   		val = val - vl;
	   		answ++;
	   		pq.pop();
		   }
		   else{
		   	pq.pop();
		   	vl = vl - val;
		   	pq.push(vl);
		   	break;
		   }
	   }

	   
	}
	cout<<answ<<endl;
}
	
	
}
