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 <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long llo;
#define mp make_pair
#define pb push_back
#define a first
#define b second
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
llo n;
cin>>n;
llo ac;
vector<pair<llo,llo>> aa;
vector<pair<llo,llo>> bb;
for(llo i=0;i<n+1;i++){
cin>>ac;
aa.pb({ac,i});
}
for(llo j=0;j<n;j++){
cin>>ac;
bb.pb({ac,j});
}
sort(aa.begin(),aa.end());
sort(bb.begin(),bb.end());
llo ans[n];
multiset<llo,std::greater<llo>> cc;
for(llo i=0;i<n;i++){
ans[i]=aa[i].a-bb[i].a;
cc.insert(ans[i]);
}
llo ans2[n];
ans2[aa[n].b]=max(*(cc.begin()),(llo)0);
for(llo i=n-1;i>=0;i--){
auto it=cc.find(ans[i]);
cc.erase(it);
ans[i]=aa[i+1].a-aa[i].a+ans[i];
cc.insert(ans[i]);
// cout<<i<<" "<<ans[i]<<endl;
ans2[aa[i].b]=max(*(cc.begin()),(llo)0);
}
for(llo i=0;i<n+1;i++){
cout<<ans2[i]<<" ";
}
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... |