이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
pair<int,int> a[n+2];
int b[n+1];
int ans[n+2];
for(int i=1;i<=n+1;i++){
cin >> a[i].first;
a[i].second=i;
}
for(int i=1;i<=n;i++){
cin >> b[i];
}
sort(b+1,b+n+1);
sort(a+1,a+n+2);
int firstdiff[n+1];
multiset<int> s;
for(int i=1;i<=n;i++){
firstdiff[i]=max(0LL,a[i].first-b[i]);
}
int secoddiff[n+1];
for(int i=1;i<=n;i++){
secoddiff[i]=max(0LL,a[i+1].first-b[i]);
s.insert(secoddiff[i]);
}
for(int i=1;i<=n+1;i++){
auto it=s.end();
it--;
int x=*it;
ans[a[i].second]=x;
if(i==n+1){
break;
}
s.erase(s.find(secoddiff[i]));
s.insert(firstdiff[i]);
}
for(int i=1;i<=n+1;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... |