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<vector>
#include<algorithm>
#include<utility>
#include<set>
using namespace std;
//想10 實作10
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<pair<int, int> >a(n+1);
vector<int> b(n);
vector<int>ans(n);
for (int i = 0 ; i < n+1 ; i++) {
cin >> a[i].first;
a[i].second = i;
}
for (auto &i : b) cin >> i;
sort(a.begin(), a.end());
sort(b.begin(), b.end());
for (int i = 0 ; i < n ; i++) {
ans[i] = max(a[i+1].first - b[i], 0);
}
vector<int>out(n+1);
multiset<int>st;
for (auto i : ans) st.insert(i);
for (int i = 0 ; i < n+1 ; i++) {
out[a[i].second] = *st.rbegin();
if (i == n) break;
st.erase(st.find(ans[i]));
ans[i] = max(a[i].first - b[i], 0);
st.insert(ans[i]);
}
for (int i = 0 ; i < n+1 ; i++) {
cout << out[i] << " ";
}
cout << "\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |