이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int INF = 1e13;
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<int> arr(2*n+1);
for(int i=1;i<=2*n;i++)cin>>arr[i];
vector<int> B(n);
for(int&i:B)cin>>i;
sort(B.begin(),B.end());
vector<int> C(n);
for(int&i:C)cin>>i;
sort(C.begin(),C.end());
int ans = INT64_MAX;
for(int i=1;i<=n+1;i++){
vector<int> pota,potb;
for(int j=i;j<i+n;j++)pota.emplace_back(arr[j]);
for(int j=1;j<i;j++)potb.emplace_back(arr[j]);
for(int j=i+n;j<=2*n;j++)potb.emplace_back(arr[j]);
sort(pota.begin(),pota.end());
sort(potb.begin(),potb.end());
{
int myans = 0;
for(int j=0;j<n;j++)myans=max(myans,abs(pota[j]-B[j]));
for(int j=0;j<n;j++)myans=max(myans,abs(potb[j]-C[j]));
ans=min(ans,myans);
}
swap(pota,potb);
{
int myans = 0;
for(int j=0;j<n;j++)myans=max(myans,abs(pota[j]-B[j]));
for(int j=0;j<n;j++)myans=max(myans,abs(potb[j]-C[j]));
ans=min(ans,myans);
}
}
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... |