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<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<cmath>
typedef long long ll;
using namespace std;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<int> vec(2 * n + 1);
for(int i = 1; i <= 2 * n; i++) cin >> vec[i];
vector<int> b(n + 1), c(n + 1);
for(int i = 1; i <= n; i++) cin >> b[i];
for(int i = 1; i <= n; i++) cin >> c[i];
sort(c.begin(), c.end());
sort(b.begin(), b.end());
ll ans = 2e18;
for(int i = 1; i <= n + 1; i++){
vector<int> tmp;
for(int j = i; j < i + n; j++) tmp.push_back(vec[j]);
vector<int> tmp2;
for(int j = 1; j < i; j++) tmp2.push_back(vec[j]);
for(int j = i + n; j <= 2 * n; j++) tmp2.push_back(vec[j]);
sort(tmp.begin(), tmp.end());
sort(tmp2.begin(), tmp2.end());
ll sum = 0;
for(int j = 1; j <= n; j++) sum = max(sum, 1ll * abs(tmp[j - 1] - b[j]));
for(int j = 1; j <= n; j++) sum = max(sum, 1ll * abs(tmp2[j - 1] - c[j]));
ans = min(ans, sum);
sum = 0;
for(int j = 1; j <= n; j++) sum = max(sum, 1ll * abs(tmp[j - 1] - c[j]));
for(int j = 1; j <= n; j++) sum = max(sum, 1ll * abs(tmp2[j - 1] - b[j]));
ans = min(ans, sum);
}
cout << ans << "\n";
}
// g++ pC.cpp -std=c++17 -Wshadow -Wall -fsanitize=undefined -fsanitize=address -o run
# | 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... |