이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |