#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx")
const int N = (int)5000 + 7, inf = (int)1e9 + 7, mod = (int)1e9 + 7;
const long long linf = (long long)1e18 + 7;
const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1},
          dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
using namespace std;
int n;
int a[N];
int second[N];
int dp[N][N];
int pref[N][N];
int get(int L, int R) {
  int now = second[R] - second[L - 1];
  int l = 0, r = L - 1, res = L;
  while (l <= r) {
    int mid = l + r >> 1;
    if (second[L - 1] - second[mid - 1] <= now)
      res = mid, r = mid - 1;
    else
      l = mid + 1;
  }
  return res;
}
int main() {
  ios_base ::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    second[i] = second[i - 1] + a[i];
  }
  memset(dp, 0x3f3f, sizeof(dp));
  memset(pref, 0x3f3f, sizeof(pref));
  for (int i = 0; i <= n; i++) {
    pref[0][i] = 0;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = i; j >= 1; j--) {
      int l = get(j, i);
      if (l < j)
        dp[i][i - j + 1] = min(dp[i][i - j + 1], pref[j - 1][j - l] + (i - j));
    }
    for (int j = 1; j <= n; j++) {
      pref[i][j] = j > 1 ? min(pref[i][j - 1], dp[i][j]) : dp[i][j];
    }
  }
  int ans = inf;
  for (int i = 1; i <= n; i++) {
    ans = min(ans, dp[n][i]);
  }
  cout << ans << '\n';
  exit(0);
}
