#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a))
#define lowbit(x) ((x)&(-x))
using namespace std ;
typedef long long ll ;
typedef unsigned long long ull ;
typedef pair <int,int> PII ;
typedef pair <double,double> PDD ;
const int N = 1e5 + 5 ;
const double eps = 1e-8 ;
const int inf = 0x3f3f3f3f ;
int n , m , a[N] ;
void solve() {
    int n; cin >> n;
    priority_queue<ll, vector<ll>, greater<ll>>q;
    ll s = 0;
    for (int i = 1; i <= n; ++i) {
        ll x; cin >> x;
        s += x;
        q.push(x);
        while (s < 0) {
            s -= q.top();
            q.pop();
        }
    }
    cout << q.size();
}
int main()
{
	solve() ;
	return 0 ;
}
