#include <bits/stdc++.h>
using namespace std;
int dp[5050][5050];
int dp2[5050][5050];
int h[100500];
int hs[100500];
int n;
int getH(int L, int R) { return hs[R] - (L == 0 ? 0 : hs[L - 1]); }
int getMin(int pos, int h) {
  int L = 0, R = pos + 1;
  while (R - L > 1) {
    int M = (R + L) / 2;
    if (getH(pos - M + 1, pos) > h)
      R = M;
    else
      L = M;
  }
  return L;
}
int main() {
  for (int i = 0; i < 5050; ++i) {
    for (int j = 0; j < 5050; ++j) dp[i][j] = 100500;
  }
  dp[0][0] = 0;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &h[i]);
    hs[i] = hs[i - 1] + h[i];
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j < i; ++j) {
      dp[i][j] =
          min(dp[i][j], dp2[i - j][getMin(i - j, getH(i - j + 1, i))] + j - 1);
    }
    dp[i][i] = i - 1;
    for (int j = 0; j <= n; ++j)
      dp2[i][j] = (j == 0 ? dp[i][j] : min(dp[i][j], dp2[i][j - 1]));
  }
  cout << dp2[n][n];
  return 0;
}
