이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |