// AIM ABOVE THE MARK TO HIT THE MARK //




#include<bits/stdc++.h>
using namespace std;

#define ff             first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)


int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int n;
	cin >> n;
	int arr[n];

	int sum = 0;
	int ans = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> arr[i];

	}
	pqs q;

	for (int i = 0; i < n; i++)
	{
		sum += arr[i];
		if (sum < 0)
		{	sum -= arr[i];
			if (q.empty())
			{
				continue;
			}
			else
			{
				int num = q.top();

				if (num < arr[i])
				{
					sum -= num;

					sum += arr[i];

					q.pop();

					q.push(arr[i]);
				}
			}
		}

		else
		{
			ans++;
			if (arr[i] < 0)
			{
				q.push(arr[i]);
			}
		}
	}
	cout << ans << endl;
	return 0;
}
