#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e6 + 66;
ll A[N], b[N];
int main() { // fuck O(N) all my homies brute for O(N^2)
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int n;
cin >> n;
for (int i = 1 ; i <= n ; ++ i) {
cin >> A[i];
}
ll ans = ll(1e18);
for (int i = 1 ; i <= n ; ++ i) { // the highest point
for (int j = 1 ; j <= n ; ++ j) {
b[j] = A[j];
}
ll L = 0, R = 0; // the number of waterings of the left side and the right side
for (int j = 1 ; j < i ; ++ j) {
if (b[j + 1] < b[j] + 1) {
L += b[j] + 1 - b[j + 1];
b[j + 1] = b[j] + 1;
}
}
for (int j = n ; j > i ; -- j) {
if (b[j - 1] < b[j] + 1) {
R += b[j] + 1 - b[j - 1];
b[j - 1] = b[j] + 1;
}
}
ans = min(ans, max(L, R));
}
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Incorrect |
15 ms |
364 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Incorrect |
15 ms |
364 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |