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>
using namespace std;
#pragma GCC optimize ("Ofast")
#pragma GCC target("fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("unroll-loops")
int main () {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector<pair<int, int> > a (n + 1);
for (int i = 0; i <= n; i++) {
cin >> a[i].first;
a[i].second = i;
}
vector<int> pessoas (n);
for (int i = 0; i < n; i++) cin >> pessoas[i];
sort (a.begin(), a.end());
sort (pessoas.begin(), pessoas.end());
multiset<int> diff;
for (int i = 0; i < n; i++) diff.insert( max (a[i].first - pessoas[i], 0) );
vector<int> ans (n + 1, -1);
ans[a[n].second] = *diff.rbegin();
int last = a[n].first;
for (int i = n - 1; i >= 0; i--) {
int current = max (a[i].first - pessoas[i], 0);
diff.erase(diff.lower_bound(current));
diff.insert( max (last - pessoas[i], 0) );
ans[a[i].second] = *diff.rbegin();
last = a[i].first;
}
for (int i = 0; i <= n; i++) cout << ans[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... |