#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000007;
int dp[5005][5005];
long long sum[5005];
int main() {
  int n, a[5005] = {};
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", a + i);
    sum[i] = sum[i - 1] + a[i];
  }
  memset(dp, 63, sizeof(dp));
  memset(dp[0], 0, sizeof(dp[0]));
  for (int i = 1; i <= n; i++) {
    for (int j = i; j >= 1; j--) {
      long long h = sum[i] - sum[j - 1];
      int x = lower_bound(sum, sum + n, sum[j - 1] - h) - sum;
      dp[i][j] = min(dp[i][j + 1], dp[j - 1][x + 1] + i - j);
    }
  }
  printf("%d\n", dp[n][1]);
}
