#include<bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long n;
cin >> n;
pair<long long, long long> arr[n+1];
long long ties[n];
for(long long i=0; i<=n; i++){
cin >> arr[i].first;
arr[i].second = i;
}
for(long long i=0; i<n; i++){
cin >> ties[i];
}
sort(arr, arr+n+1);
sort(ties, ties+n);
long long ans[n+1];
multiset<long long, greater<long long>> st;
for(long long i=1; i<=n; i++){
st.insert(abs(ties[i-1]-arr[i].first));
ans[0]=*st.begin();
}
for(long long taken = 1; taken<=n; taken++){
st.erase(st.find(abs(arr[taken].first-ties[taken-1])));
st.insert(abs(arr[taken-1].first-ties[taken-1]));
ans[taken]=*st.begin();
}
long long finans[n+1];
for(long long i=0; i<=n; i++){
finans[arr[i].second]=ans[i];
}
for(long long i=0; i<=n; i++){
cout << finans[i] << ' ';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |