#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+10;
const int INF = 1e9+7;
int dat[4*N], a[N], n;
int Min(int i, int j) {
    return a[i] < a[j] ? i : j;
}
void push_up(int v) {
    int chl = v*2+1, chr=v*2+2;
    dat[v] = Min(dat[chl], dat[chr]);
}

void build(int v=0, int l=0, int r=n) {
    if (l + 1 == r) {
        dat[v] = l;
    } else {
        int mid = (l+r)/2, chl = v*2+1, chr=v*2+2;
        build(chl, l, mid);
        build(chr, mid, r);
        push_up(v);
    }
}

int query(int L, int R, int v=0, int l=0, int r=n) {
    if (r <= L || R <= l) return N-1;
    if (L <= l && r <= R) return dat[v];
    int mid = (l+r)/2, chl = v*2+1, chr=v*2+2;
    return Min(query(L,R, chl, l, mid), query(L,R, chr, mid, r));
}

void update(int x, int y, int v = 0, int l = 0, int r=n) {
    if (l + 1 == r) {
        a[x] = y;
    } else {
        int mid = (l+r)/2, chl = v*2+1, chr=v*2+2;
        if (x < mid) update(x, y, chl, l, mid);
        else update(x, y, chr, mid, r);
        push_up(v);
    }
}

int main() {
    a[N-1] = INF;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) scanf("%d",a+i);
    build();
    ll sum = 0;
    int ans = n;
    for (int i = 0; i < n; i++) {
        sum += a[i];
        while (sum < 0) {
            int x = query(0, i+1);
            assert(a[x] < 0);
            sum -= a[x];
            --ans;
            update(x, 0);
        }
    }
    printf("%d\n",ans);
}