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;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
vector<pair<int, int>> a;
vector<int> b;
int n, push_a, sum_a = 0, sum_b = 0;
cin >> n;
for(int i = 0; i <= n; i++){
cin >> push_a;
sum_a += push_a;
a.push_back({push_a, i});
}
for(int i = 0; i < n; i++){
cin >> push_a;
sum_b += push_a;
b.push_back(push_a);
}
sort(b.begin(), b.end());
sort(a.begin(), a.end());
/*
int pomoc = a[0].first;
a[0].first = 0;
int k = 0;
for(int j = 0; j <= n; j++){
if(a[j].first == 0){
j++;
}
cout << a[j].first << " " << b[k] << endl;
wyn += max(0, a[j].first - b[k]);
k++;
}
int tab[n + 1];
tab[a[0].second] = wyn;
cout << a[0].second << " " << wyn << endl;
for(int i = 0; i < n; i++){
wyn -= max(0, (a[i + 1].first - b[i]));
wyn += max(0, (a[i].first - b[i]));
tab[a[i + 1].second] = wyn;
}
for(int i = 0; i <= n; i++){
cout << tab[i] << " ";
}
*/
int pref[n + 1], suf[n + 1], tab[n + 1];
pref[0] = 0;
suf[n] = 0;
int max_pref_suf = 0;
for(int i = 1; i <= n; i++){
pref[i] = max(max_pref_suf, a[i - 1].first - b[i - 1]);
max_pref_suf = pref[i];
}
max_pref_suf = 0;
for(int i = n - 1; i >= 0; i--){
suf[i] = max(max_pref_suf, a[i + 1].first - b[i]);
max_pref_suf = suf[i];
}
for(int i = 0; i <= n; i++){
tab[a[i].second] = max(pref[i], suf[i]);
}
for(int i = 0; i <= n; i++){
cout << tab[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... |