#include <bits/stdc++.h>
using namespace std;
const int MX = 5001, inf = (1 << 30);
int sum[MX], arr[MX];
int n;
int dp[MX][MX];
int get(int x, int y) { return sum[y] - sum[x - 1]; }
int main() {
  scanf("%d", &n);
  for (int j = 1; j <= n; j++) {
    scanf("%d", &arr[j]);
    sum[j] = arr[j] + sum[j - 1];
  }
  for (int j = 0; j < MX; j++)
    for (int i = 0; i < MX; i++) dp[j][i] = inf;
  for (int j = 1; j <= n; j++) dp[1][j] = j - 1;
  for (int j = 2; j <= n; j++) {
    int it = j;
    int xx = n + 1;
    for (int i = j; i <= n; i++) {
      if (get(j, i) < arr[j - 1])
        dp[j][i] = inf;
      else {
        xx = i;
        break;
      }
    }
    int best = inf;
    for (int i = xx; i <= n; i++) {
      while (it > 1 && get(it - 1, j - 1) <= get(j, i)) {
        best = min(best, dp[it - 1][j - 1]);
        it--;
      }
      dp[j][i] = min(dp[j][i], best + i - j);
    }
  }
  int ans = inf;
  for (int j = 1; j <= n; j++) ans = min(ans, dp[j][n]);
  cout << ans << endl;
}
