#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <cstring>
#include <cctype>
#include <functional>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <stack>
#include <bitset>

#define ll long long
#define ull unsigned long long
#define pb emplace_back
#define gtc cin.get()
#define endl '\n'

using namespace std;

int main()
{
	ios::sync_with_stdio(0);
	int n;
	cin >>n;
	priority_queue<int>q;
	ll res=0,ans=0;
	while(n--)
	{
		int x;
		cin >>x;
		if(x>=0)
			ans++,res+=x;
		else if(x<0&&res+x>=0){
			ans++,res+=x;
			q.push(-x);
		}
		else if(!q.empty()&&-x<q.top()){
			res+=x,res+=q.top();
			q.pop();
			q.push(-x);
		}
	}
	cout<<ans;
}
