// O(n^2) のTLE解 #include using namespace std; int solve() { int n; cin >> n; vector A(n); for (int i = 0; i < n; i++) cin >> A[i]; const int inf = 1e9; vector> dp(n+1, vector(n+1, inf)); dp[0][0] = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < i + 1; j++) { if (dp[i][j] >= inf) continue; if (dp[i][j] < A[i]) { dp[i+1][j] = min(dp[i+1][j], A[i]); } dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j] + 1); } } for (int j = 0; j < n; j++) { if (dp[n][j] < inf) { return j; } } assert(false); } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << solve() << endl; return 0; }