#include <bits/stdc++.h>
using namespace std;
int n,b[200005];
pair<int,int> a[200005];
int ans[200005];
int d1[200005],d2[200005];
int maxpref[200005],maxsuf[200005];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
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(b + 1,b + n + 1);
sort(a + 1,a + n + 2);
for (int i = 1; i <= n; i++)
d1[i] = abs(a[i].first - b[i]);
for (int i = 1; i <= n; i++)
d2[i] = abs(a[i + 1].first - b[i]);
maxpref[0] = 0;
maxsuf[n + 1] = 0;
for (int i = 1; i <= n; i++)
maxpref[i] = max(maxpref[i - 1],d1[i]);
for (int i = n; i >= 1; i--)
maxsuf[i] = max(maxsuf[i + 1],d2[i]);
for (int i = 1; i <= n + 1; i++)
ans[a[i].second] = max(maxpref[i - 1],maxsuf[i]);
for (int i = 1; i <= n + 1; i++)
cout << ans[i] << ' ';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Incorrect |
1 ms |
4560 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Incorrect |
1 ms |
4560 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Incorrect |
1 ms |
4560 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |