#ifndef LOCAL
#pragma GCC Optimize("O3,Ofast,unroll-loops")
#pragma GCC Target("bmi,bmi2,avx,avx2")
#endif
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define int ll
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define pii pair<int, int>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin() (x).rend()
#ifndef LOCAL
#define endl "\n"
#endif
mt19937 rnd(11);
vector<int> solve(vector<int> &a, vector<int> &b, int x) {
int n = a.size() / 2;
vector<int> ans(n, 1);
for (int i = 0; i < n; ++i) {
vector<int> now;
for (int j = 0; j < n; ++j) {
now.pb(a[i + j]);
}
sort(all(now));
for (int j = 0; j < n; ++j) {
if (abs(now[j] - b[j]) > x) {
ans[i] = 0;
break;
}
}
}
int ch = 0;
for (int i = 1; i < n; ++i) {
if (ans[i] != ans[i - 1]) {
++ch;
}
}
assert(ch <= 4);
return ans;
}
vector<int> solve(vector<int> &a, vector<int> &b) {
int n = a.size() / 2;
vector<int> ans(n);
for (int i = 0; i < n; ++i) {
vector<int> now;
for (int j = 0; j < n; ++j) {
now.pb(a[i + j]);
}
sort(all(now));
for (int j = 0; j < n; ++j) {
ans[i] = max(ans[i], abs(now[j] - b[j]));
}
}
return ans;
}
void solve() {
int n;
cin >> n;
vector<int> a(n * 2);
for (auto &x : a) {
cin >> x;
}
vector<int> b(n);
for (auto &x : b) {
cin >> x;
}
vector<int> c(n);
for (auto &x : c) {
cin >> x;
}
sort(all(b));
sort(all(c));
vector<int> a_(a.size());
for (int i = 0; i < a.size(); ++i) {
a_[i] = a[(i + n) % a.size()];
}
vector<int> ansB = solve(a, b);
vector<int> ansC = solve(a, c);
vector<int> ansB_ = solve(a_, c);
vector<int> ansC_ = solve(a_, b);
int ans = 1e18;
for (int i = 0; i < n; ++i) {
ans = min(ans, max(ansB[i], ansB_[i]));
ans = min(ans, max(ansC[i], ansC_[i]));
}
solve(a, b, ans);
solve(a, c, ans);
solve(a_, c, ans);
solve(a_, b, ans);
cout << ans << endl;
}
signed main() {
#ifdef LOCAL
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#else
ios::sync_with_stdio(false);
cin.tie(0);
#endif
int t = 1;
// cin >> t;
while (t--) {
solve();
}
}
| # | 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... |