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(){
int n;
cin >> n;
vector<pair<int, int>> availableties(n+1);
for(int i = 0; i<=n; i++){
cin >> availableties[i].first;
availableties[i].second = i;
}
vector<int> initialties(n);
for(int i = 0; i<n; i++){
cin >> initialties[i];
}
sort(initialties.begin(), initialties.end());
sort(availableties.begin(), availableties.end());
vector<int> ans(n+1);
vector<int> pref(n+1);
for(int i = 1; i<=n; i++){
pref[i] = max(pref[i-1], max(0, availableties[i-1].first-initialties[i-1]));
}
vector<int> suff(n+1);
for(int i = n-1; i>=0; i--){
suff[i] = max(suff[i+1], max(0, availableties[i+1].first-initialties[i]));
}
for(int i = 0; i<n+1; i++){
// assign the ith tie to the ceo
ans[availableties[i].second] = max(pref[i], suff[i]);
}
for(int i = 0; i<=n; i++){
cout << ans[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... |