#include <bits/stdc++.h>
#define startt ios_base::sync_with_stdio(false);cin.tie(0);
typedef unsigned long long ull;
typedef long long  ll;
using namespace std;
#define vint vector<int>
#define all(v) v.begin(), v.end()
#define sz(a) (int)a.size()
#define MOD 1000000007
#define MOD2 998244353
#define MX 1000000000
#define nax 100005
#define MXL 1000000000000000000
#define PI 3.14159265
#define pb push_back
#define pf push_front
#define sc second
#define fr first
#define endl '\n' //delete if interactive
#define ld long double
#define mp make_pair

void solve(){
	ll n;cin>>n;
	priority_queue<ll> pq;
	ll x;ll sum=0,num=0;;
	for(int i=0;i<n;i++){
		cin>>x;
		pq.push(-x);
		sum+=x;num++;
		if(sum<0){
			sum+=pq.top();
			num--;
			pq.pop();
		}
	}cout<<num<<endl;
}

int main(){
	solve();
	return 0;
}
