#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
#define pb push_back
#define rsz resize
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
using pi = pair<int,int>;
#define f first
#define s second
#define mp make_pair
const int MX = 500005;
const int MOD = (int) (1e9 + 7);
const ll INF = (ll) 1e18;
int a[MX];
int pre[MX], suf[MX];
int n;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n; i++) {
int j, k, c;
if (i != 0) {
for (j = i - 1, k = 1, c = 1; j >= 0; j -= k, k += 2, c++) {
suf[j] = max(suf[j], a[i] + c);
}
}
if (i != n - 1) {
for (j = i + 1, k = 1, c = 1; j < n; j += k, k += 2, c++) {
pre[j] = max(pre[j], a[i] + c);
}
}
}
for (int i = 1; i < n; i++) {
pre[i] = max(pre[i - 1], pre[i]);
}
for (int i = n - 2; i >= 0; i--) {
suf[i] = max(suf[i + 1], suf[i]);
}
for (int i = 0; i < n; i++) {
cout << max(pre[i], suf[i]) - a[i] << '\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
17 ms |
1024 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
34 ms |
1432 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
52 ms |
1400 KB |
Output is correct |
2 |
Correct |
48 ms |
1308 KB |
Output is correct |
3 |
Correct |
49 ms |
1660 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
89 ms |
1912 KB |
Output is correct |
2 |
Correct |
90 ms |
1912 KB |
Output is correct |
3 |
Correct |
94 ms |
2528 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
301 ms |
4216 KB |
Output is correct |
2 |
Correct |
315 ms |
5920 KB |
Output is correct |
3 |
Correct |
298 ms |
6012 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
597 ms |
8084 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1002 ms |
11384 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1024 ms |
8824 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |