이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin>>n;
vector<pair<int, int>> neckties(n+1);
vector<int> employees(n);
for (int i=0;i<n+1;i++){
cin>>neckties[i].first;
neckties[i].second=i;
}
for (int i=0;i<n;i++) cin>>employees[i];
sort(neckties.begin(), neckties.end(), greater<pair<int, int>>());
sort(employees.begin(), employees.end(), greater<int>());
vector<int> noSkipOut(n+1);
noSkipOut[0]=neckties[0].first-employees[0];
noSkipOut[n]=-1;
for (int i=1;i<n;i++){
noSkipOut[i]=max(noSkipOut[i-1], neckties[i].first-employees[i]);
}
vector<int> skipOut(n+1);
skipOut[0]=-1;
skipOut[n]=neckties[n].first-employees[n-1];
for (int i=n;i>0;i--){
skipOut[i]=max(skipOut[i+1], neckties[i].first-employees[i-1]);
}
vector<int> finalOut(n+1);
finalOut[neckties[0].second]=skipOut[1];
finalOut[neckties[n].second]=noSkipOut[n-1];
for (int i=0;i<n+1;i++){
finalOut[neckties[i].second]=max(noSkipOut[i-1], skipOut[i+1]);
}
for (int x:finalOut) cout<<x<<" ";
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... |