#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define endl '\n'

int32_t main() {
   IOS;
   int n; cin >> n;
   int a[n];
   for (int i = 0; i < n; i++)
      cin >> a[i];
   int sum = 0;
   priority_queue<int, vector<int>, greater<int> > pq;
   for (int i = 0; i < n; i++) {
      sum += a[i];
      pq.push(a[i]);
      while (sum < 0) {
         sum -= pq.top();
         pq.pop();
      }
   }
   cout << pq.size() << endl;

}
