#include <bits/stdc++.h>
using namespace std;
 
#define int long long int
const int mod = 1e9+7;
template <typename Type>
istream &operator>>(istream &in, vector<Type> &vec) {
    int n = vec.size();
    for (int i = 0; i < n; i++)
        in >> vec[i];
    return in;
}
template <typename Type>
ostream &operator<<(ostream &out, vector<Type> &vec) {
    for (auto val : vec)
        out << val << " ";
    return out;
}

vector<int> p, d;
int n, h;

void apply(int i, int value) 
{
  p[i] += value;
  if (i < n) d[i] += value;
}

void build(int i) 
{
  while (i > 1) i >>= 1, p[i] = min(p[i<<1], p[i<<1|1]) + d[i];
}

void push(int idx) 
{
  for (int s = h; s > 0; --s) 
  {
    int i = idx >> s;
    if (d[i] != 0) 
    {
      apply(i<<1, d[i]);
      apply(i<<1|1, d[i]);
      d[i] = 0;
    }
  }
}
void inc(int l, int r, int value) 
{
  l += n, r += n;
  int l0 = l, r0 = r;
  for (; l < r; l >>= 1, r >>= 1) 
  {
    if (l&1) apply(l++, value);
    if (r&1) apply(--r, value);
  }
  build(l0);
  build(r0 - 1);
}
int query(int l, int r) {
  l += n, r += n;
  push(l);
  push(r - 1);
  int res = 2e9;
  for (; l < r; l >>= 1, r >>= 1) {
    if (l&1) res = min(res, p[l++]);
    if (r&1) res = min(p[--r], res);
  }
  return res;
}

#undef int
int main()
{   
#define int long long int
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin>>n;
    h = sizeof(int) * 8 - __builtin_clzll(n);
    vector<int> v(n);
    cin>>v;
    int s = 0;
    while(v[s] < 0)
        s++;
    if(s == n)
    {
        cout<<0<<endl;
        return 0;
    }
    p.resize(2*n);
    d.resize(2*n);
    p[s+n] = v[s];
    vector< pair<int, int> > negs;
    int ans = 1;
    for(int i = s+1;i<n;i++)
    {
        if(v[i] >= 0)
            p[i+n] = p[n+i-1] + v[i], ans++;
        else
            negs.push_back({v[i], i}), p[i+n] = p[n+i-1];
    }
    for(int i = n-1;i;i--)
        p[i] = min(p[i<<1], p[i<<1|1]);
    sort(negs.begin(), negs.end(), greater< pair<int, int> >());
    for(auto pa: negs)
    {
        if(query(pa.second, n) >= -pa.first)
            ans++, inc(pa.second, n, pa.first);
    }
    cout<<ans<<endl;

 
    return 0;
}