/*

   author : dunk_066

*/

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int mod=1e9+7;
#define FAST ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define all(c) c.begin(),c.end()
#define pb push_back
#define vi(a,x) vector<int>a(x)
#define vl(a,x) vector<ll>a(x)
#define ss second
#define ff first

void solve(){
     int n; cin >> n;
	priority_queue<long long, vector<long long>, greater<long long> > pq;
	long long S = 0;
	
	for(int i = 1;i <= n;i++){
		long long x; cin >> x;
		S += x;
		pq.push(x);
		
		while(S < 0){
			S -= pq.top();
			pq.pop();
		}
	}
	
	cout << (int) pq.size();
}

int main(){
        FAST;
	int t=1;//cin>>t;
	while(t--)
	solve();
        #ifndef ONLINE_JUDGE
        cout << "\nTime Elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec\n";
        #endif
	return 0;
}

// ============== Notes =============== //
// common bugs
// - int overflow (especially intermediate expressionns)
// - array bounds (indices bigger than MAXN?)
// - special cases (n=1? graph not connected?)