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>
#define ll long long
using namespace std;
const int maxn=3e5+5;
int N,niz[2*maxn],R[maxn],B[maxn];
int resi(){
vector<int> A,BB;
int ret=1e9;
for(int p=1;p<=N+1;p++){
int k=p+N-1;
int tmp=0;
A.clear();
BB.clear();
for(int i=1;i<=2*N;i++)
if(i>=p and i<=k)
A.push_back(niz[i]);
else
BB.push_back(niz[i]);
sort(A.begin(),A.end());
sort(BB.begin(),BB.end());
for(int i=1;i<=N;i++){
tmp=max(tmp,abs(R[i]-A[i-1]));
tmp=max(tmp,abs(B[i]-BB[i-1]));
}
ret=min(ret,tmp);
}
return ret;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cin>>N;
for(int i=1;i<=2*N;i++)
cin>>niz[i];
for(int i=1;i<=N;i++)
cin>>R[i];
for(int i=1;i<=N;i++)
cin>>B[i];
sort(R+1,R+1+N);
sort(B+1,B+1+N);
int res=resi();
for(int i=1;i<=N;i++)
swap(R[i],B[i]);
res=min(res,resi());
cout<<res<<"\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... |