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

#define fo(i, x, y) for (int i = (x); i <= (y); ++i)
#define fd(i, x, y) for (int i = (x); i >= (y); --i)

typedef long long ll;

const int maxn = 2e5 + 5;

int n;
ll a[maxn], pre[maxn];
priority_queue<ll> que;

int getint()
{
	char ch;
	int res = 0, p;
	while (!isdigit(ch = getchar()) && (ch ^ '-'));
	p = ch == '-'? ch = getchar(), -1 : 1;
	while (isdigit(ch))
		res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar();
	return res * p;
}

int main()
{
	//freopen("t.in", "r", stdin);
	n = getint();
	fo(i, 1, n) a[i] = getint();
	ll s = 0, cnt = 0, ans = 0;
	fo(i, 1, n)
	{
		s += a[i]; cnt++;
		que.push(-a[i]);
		if (s < 0) s += que.top(), que.pop(), cnt--;
		ans = max(ans, cnt);
	}
	printf("%lld\n", ans);
	return 0;
}
