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;
using ll = long long; using pii = pair<ll,ll>;
const ll INF = 2e18;
int main() {
ios_base::sync_with_stdio(false); cin.tie(0);
ll N; cin >> N;
ll ans = INF;
ll a[2*N];
vector<ll> b,c;
for (ll i=0;i<(2*N);i++) {
cin >> a[i];
}
for (ll i=0;i<N;i++) {
ll x; cin >> x;
b.push_back(x);
}
for (ll i=0;i<N;i++) {
ll x; cin >> x;
c.push_back(x);
}
sort(b.begin(),b.end());
sort(c.begin(),c.end());
for (ll i=0;i<N;i++) {
ll fval = -INF;
ll fval2 = -INF;
vector<ll> b1;
for (ll j=i;j<(i+N);j++) {
b1.push_back(a[j]);
}
sort(b1.begin(),b1.end());
for (ll j=0;j<N;j++) {
fval = max(fval,abs(b1[j]-b[j]));
fval2 = max(fval2,abs(b1[j]-c[j]));
}
vector<ll> c1;
for (ll j=0;j<i;j++) {
c1.push_back(a[j]);
}
for (ll j=(i+N);j<(2*N);j++) {
c1.push_back(a[j]);
}
sort(c1.begin(),c1.end());
for (ll j=0;j<N;j++) {
fval = max(fval,abs(c1[j]-c[j]));
fval2 = max(fval2,abs(c1[j]-b[j]));
}
ans = min(ans,fval);
ans = min(ans,fval2);
}
cout << ans << "\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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |