#include <bits/stdc++.h>
using namespace std;
const int mx = 5e3 + 1, Mod = 1e9 + 7;
int n, a[mx];
int dp[mx][mx];
int ps[mx];
int fen[mx][mx];
void add(int w, int nod, int x) {
  for (++nod; nod <= n; nod += nod & (-nod)) fen[w][nod] = min(fen[w][nod], x);
}
int get(int w, int nod) {
  if (w < 0) return 0;
  int res = Mod;
  for (++nod; nod > 0; nod -= nod & (-nod)) res = min(res, fen[w][nod]);
  return res;
}
int bs(int nod, int val) {
  int L = -1, R = nod + 1, mid;
  while (R - L > 1) {
    mid = (L + R) / 2;
    if (ps[nod] - ps[nod - mid] + a[nod - mid] > val)
      R = mid;
    else
      L = mid;
  }
  return L;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  ps[0] = a[0];
  for (int i = 1; i < n; i++) ps[i] = ps[i - 1] + a[i];
  for (int i = 0; i <= n; i++)
    for (int j = 0; j <= n; j++) fen[i][j] = Mod;
  add(0, 0, 0);
  for (int i = 1; i < n; i++) {
    for (int j = 0; j <= i; j++) {
      dp[i][j] = min(
          Mod, j + get(i - j - 1, bs(i - j - 1, ps[i] - ps[i - j] + a[i - j])));
      add(i, j, dp[i][j]);
    }
  }
  cout << get(n - 1, n - 1) << '\n';
  return 0;
}
