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>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long n,a;
cin >> n;
vector<long long> ans(n+1);
vector<pair<long long,long long>> haha(n+1);
vector<long long> bruh(n);
for(long long i = 0; i <= n; i++) {
cin >> a;
haha[i] = {a,i};
}
for(long long i = 0; i < n; i++) {
cin >> bruh[i];
}
sort(haha.begin(),haha.end());
sort(bruh.begin(),bruh.end());
vector<long long> pr(n+1);
vector<long long> su(n+1);
for(long long i = 1; i <= n; i++) {
pr[i] = max(haha[i-1].first-bruh[i-1],0LL);
pr[i] = max(pr[i],pr[i-1]);
}
for(long long i = n-1; i >= 0; i--) {
su[i] = max(haha[i+1].first-bruh[i],0LL);
su[i] = max(su[i],su[i+1]);
}
for(long long i = 0; i < n+1; i++) {
ans[haha[i].second] = max(pr[i],su[i]);
}
for(long long i = 0; i < n+1; i++) {
cout << ans[i] << " ";
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |