#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int const N = 1000 * 1000 + 16;
int const M = 1000 * 1000 * 1000 + 7;
int n;
int a[5010];
int b[5010];
int len[5010];
pair<int, int> dp[5010][5010];
int main() {
  cin.tie(0);
  cin.sync_with_stdio(0);
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  dp[0][len[0]++] = {0, 0};
  for (int i = 0; i <= n; ++i) {
    sort(dp[i], dp[i] + len[i]);
    b[0] = dp[i][0].second;
    for (int j = 1; j < len[i]; ++j) b[j] = min(b[j - 1], dp[i][j].second);
    int sum = 0;
    int k = -1;
    for (int j = i + 1; j <= n; ++j) {
      sum += a[j];
      while (k + 1 < len[i] && dp[i][k + 1].first <= sum) ++k;
      if (k >= 0) dp[j][len[j]++] = {sum, j - i - 1 + b[k]};
    }
  }
  cout << b[len[n] - 1];
}
