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;
#define ll long long
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
ll n; cin >> n;
vector<ll> a(n+1);
vector<ll> b(n);
vector<ll> pref(n+1, 0);
vector<ll> suf(n+1, 0);
for (int i = 0; i <= n; i++){
cin >> a[i];
}
for (int i = 0; i < n; i++){
cin >> b[i];
}
sort(a.begin(), a.end());
sort(b.begin(), b.end());
vector<ll> res(n+1);
ll aktual = 0;
for (int i = 0; i < n; i++){ // pref czyli jak usuwamy ity elem np. ostatni
ll h = a[i] - b[i];
aktual = max(aktual, h);
pref[i] = aktual;
}
res[n] = aktual;
aktual = 0;
for (int i = n-1; i > 0; i--){ // suf co jak zabierzemy ity elem laczymy na skos
ll h = a[i+1] - b[i];
aktual = max<ll>(aktual, h);
suf[i] = aktual;
}
res[0] = aktual;
for (int i = 1; i < n; i++){ // zabieramy ity
ll h = max<ll>(pref[i-1], suf[i]);
res[i] = h;
}
for (int i = 0; i <= n; i++){
cout << res[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... |