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;
const int maxn = 2e5 + 5;
int ppl[maxn], ans[maxn];
multiset<int> st;
pair<int, int> ties[maxn];
int main(){
int n; cin >> n;
for(int i = 0; i <= n; i++) cin >> ties[i].first;
for(int i = 0; i < n; i++) cin >> ppl[i];
for(int i = 0; i <= n; i++) ties[i].second = i;
sort(ppl, ppl+n);
sort(ties, ties+n+1);
for(int i = 1; i <= n; i++) st.insert(ties[i].first-ppl[i-1]);
// ans[tie[0].second] = st.rbegin();
ans[ties[0].second] = max(0, *st.rbegin());
for(int i = 0; i < n; i++){
int id = ties[i+1].second;
// cout << i << " " << id << "\n";
st.insert(ties[i].first-ppl[i]);
st.erase(st.find(ties[i+1].first-ppl[i]));
ans[id] = max(0, *st.rbegin());
}
for(int i = 0; i <= n; i++) cout << ans[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... |