#include using namespace std; struct iostream_init_struct { iostream_init_struct() { std::cin.tie(0); std::cin.sync_with_stdio(false); } } iostream_init; #include #include int N; int A[2000]; int dp[2000][2000][2]; const int INF = 2e9; int main(void) { cin >> N; for (int i = 0; i < N; ++i) { cin >> A[i]; } memset(dp, 0x3f, sizeof dp); dp[0][N - 1][0] = A[0]; dp[0][N - 1][1] = A[N - 1]; for (int i = 0; i < N; ++i) { for (int j = N - 1; j >= i; --j) { if (i - 1 >= 0) { dp[i][j][0] = min(dp[i][j][0], max(A[i], dp[i - 1][j][0] + 1)); dp[i][j][1] = min(dp[i][j][1], max(A[j], dp[i - 1][j][0] + j - (i - 1))); } if (j + 1 < N) { dp[i][j][0] = min(dp[i][j][0], max(A[i], dp[i][j + 1][1] + (j + 1) - i)); dp[i][j][1] = min(dp[i][j][1], max(A[j], dp[i][j + 1][1] + 1)); } } } int ans = INF; for (int i = 0; i < N; ++i) { ans = min(ans, dp[i][i][0]); } cout << ans << endl; }