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>
typedef long long ll;
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
int n;
cin >> n;
pair<int,int>a[n+4];
int b[n+4];
for (int i=1; i<=n+1; i++) {
cin >> a[i].first;
a[i].second=i;
}
sort(a+1,a+n+1+1);
// for (int i=1; i<=n+1; i++) {
// cout << a[i].first << " " << a[i].second << endl;
// }
for (int i=1; i<=n; i++) {
cin >> b[i];
}
sort(b+1,b+n+1);
multiset<int>s;
int ans[n+4];
map<int,int>mp;
for (int i=2; i<=n+1; i++) {
s.insert(max(a[i].first-b[i-1],0));
mp[i]=i-1;
//cout << *--s.end();
ans[a[1].second]=*--s.end();
}
//cout << ans[2] << endl;
//cout << *--s.end() << endl;
for (int i=2; i<=n+1; i++) {
int cur=max(a[i].first-b[mp[i]],0);
s.erase(s.find(cur));
s.insert(max(a[i-1].first-b[mp[i]],0));
mp[i-1]=mp[i];
//cout << i << " " << a[i].second << endl;
ans[a[i].second]=*--s.end();
}
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... |