#include<bits/stdc++.h>
using namespace std;
struct node {
	long long int val;
	int place;
};

int main()
{
	int n;
	cin >> n;
	vector<long long int>vec(n);
	for (int i = 0; i < n; i++)
		cin >> vec[i];
	long long int now = 0;
	int cnt = 0;
	priority_queue<int, vector<int>, greater<int> >q;
	for (int i = 0; i < n; i++)
	{
		if (vec[i] >= 0)
		{
			cnt++;
			now += vec[i];
		}
		else
		{
			if (now + vec[i] >= 0)
			{
				cnt++;
				now += vec[i];
				q.push(vec[i]);
			}
			else
			{
				if (!q.empty())
				{
					int min = q.top();
					if (vec[i] > min)
					{
						q.pop();
						q.push(vec[i]);
						now += vec[i] - min;
					}
				}
			}
		}
	}
	cout << cnt << '\n';

	//system("pause");
    return 0;
}
