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;
#define ll long long
int main(){
ll n;
cin >> n;
vector <ll> pracownicy(n);
vector <ll> krawaty(n+1);
vector <ll> pre(n);
vector <ll> suf(n);
unordered_map <ll, ll> wyniki;
for(int i = 0; i < n+1; i++){
cin >> krawaty[i];
}
for(int i = 0; i < n; i++){
cin >> pracownicy[i];
}
vector<ll> zapasowa = krawaty;
sort(pracownicy.begin(), pracownicy.end());
sort(krawaty.begin(), krawaty.end());
pre[0] = max(krawaty[0] - pracownicy[0], 0ll);
for(ll i = 1; i < n; i++){
pre[i] = max(pre[i-1], krawaty[i] - pracownicy[i]);
}
suf[n - 1] = max(krawaty[n]-pracownicy[n-1], 0ll);
for(ll i = n-2; i >= 0; i--){
suf[i] = max(suf[i+1],krawaty[i+1]-pracownicy[i]);
}
wyniki[krawaty[0]] = suf[0];
for(ll i = 1; i < n; i++){
wyniki[krawaty[i]] = max(suf[i], pre[i-1]);
}
wyniki[krawaty[n]] = pre[n-1];
for(ll i = 0; i < n+1; i++){
cout << wyniki[zapasowa[i]] << " ";
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |