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