#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<int, int> ii;
int maxpre[2][200005];
int n;
ii a[200005];
int b[200005];
int ans[200005];
int main() {
cin >> n;
for(int i = 1; i <= n + 1; i++) {
cin >> a[i].first;
a[i].second = i;
}
for(int i = 1; i <= n; i++) {
cin >> b[i];
}
sort(a + 1, a + n + 2);
sort(b + 1, b + n + 1);
for(int i = 1; i <= n + 1; i++) {
ans[a[i].second] = i;
}
for(int i = 1; i <= n; i++) {
maxpre[0][i] = max(maxpre[0][i - 1], a[i].first - b[i]);
}
for(int i = n; i >= 1; i--) {
maxpre[1][i] = max(maxpre[1][i + 1], a[i].first - b[i - 1]);
}
for(int i = 1; i <= n + 1; i++) {
cout << max(maxpre[0][ans[i] - 1], maxpre[1][ans[i] + 1]) << " ";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |