This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define taskname "justlongneckties"
using namespace std;
const int lim = 2e5 + 5;
const int INF = 1e9;
template<class T>void maximize(T& a, T b){
if(a < b){
a = b;
}
}
int n, a[lim], b[lim], p[lim], ans[lim];
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
if(fopen(taskname".inp", "r")){
freopen(taskname".inp", "r", stdin);
}
int n;
cin >> n;
for(int i = 0; i <= n; ){
cin >> a[++i];
}
for(int i = 1; i <= n; i++){
cin >> b[i];
}
sort(b + 1, b + n + 1);
iota(p + 1, p + n + 2, 1);
sort(p + 1, p + n + 2, [&] (int i, int j) -> bool{
return a[i] < a[j];
});
multiset<int>right;
int left = -INF;
for(int i = 1; i <= n; i++){
right.insert(a[p[i + 1]] - b[i]);
}
ans[p[1]] = *right.rbegin();
for(int i = 2; i <= n + 1; i++){
right.erase(right.find(a[p[i]] - b[i - 1]));
maximize(left, a[p[i - 1]] - b[i - 1]);
ans[p[i]] = max(right.empty() ? 0 : *right.rbegin(), left);
}
for(int i = 0; i <= n; ){
cout << max(0, ans[++i]) << " ";
}
}
Compilation message (stderr)
ho_t1.cpp: In function 'int main()':
ho_t1.cpp:15:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
15 | freopen(taskname".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |