#include<bits/stdc++.h>
#define N 2001001
#define MAX 2001
#define re register
#define inf 1e18
using namespace std;
typedef long long ll;
typedef double db;
inline void read(register ll &ret)
{
	ret=0;register char c=getchar();register bool pd=false;
	while(!isdigit(c)){pd|=c=='-';c=getchar();}
	while(isdigit(c)){ret=(ret<<1)+(ret<<3)+(c&15);c=getchar();}
	ret=pd?-ret:ret;
	return;
}
ll n,a[N],now,nowans,ans;
priority_queue<ll>q;
signed main()
{
	read(n);
	for(re int i=1;i<=n;i++)
		read(a[i]);
	for(re int i=1;i<=n;i++)
	{
		ans=max(ans,nowans);
		if(a[i]>=0)
		{
			now+=a[i];
			nowans++;
			continue;
		}
		now+=a[i];
		nowans++;
		q.push(-a[i]);
		if(now>=0)
			continue;
		while(!q.empty()&&now<0)
		{
			now+=q.top();
			nowans--;
			q.pop();
		}
		if(now<0)
			break;
	}
	ans=max(ans,nowans);
	printf("%lld\n",ans);
	exit(0);
}