#include <bits/stdc++.h>
using namespace std;
#define i64 long long
#define ld long double
#define bit(n,i) ((n>>i)&1)
#define pii pair<int,int>
#define sz(x) (int)x.size()
#define FOR(i,a,b) for(int i=a; i<=b; i++)
#define FOD(i,a,b) for(int i=a; i>=b; i--)
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(),x.end()
#define __sumairu__ signed main()
#define die_hard_onimai_fan void seggs()
#define file(name) if(fopen(name".inp","r")){freopen(name".inp","r",stdin);freopen(name".out","w",stdout);}
#define brute(name) if(fopen(name".inp","r")){freopen(name".inp","r",stdin);freopen(name".ans","w",stdout);}
#define TIME (1.0*clock()/CLOCKS_PER_SEC)
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ai(n) array<int,n>
#define dbg(x) {cerr<<#x<<' '<<x<<endl;}
#define dbgArr(arr,n) {cerr<<#arr;FOR(_i,1,n)cerr<<' '<<(arr)[_i];cerr<<endl;}
template <typename T,typename U>
ostream& operator<<(ostream &os,pair<T,U>p){
return os<<"{"<<p.fi<<", "<<p.se<<"}";
}
mt19937_64 rd(chrono::steady_clock::now().time_since_epoch().count());
i64 Rand(i64 l,i64 r)
{
i64 ans=l+1ll*rd()*rd()%(r-l+1);
assert(l<=ans&&ans<=r);
return ans;
}
//const i64 base=1e9+7;
//const i64 mod=(1ll<<53)+5;
#define i64 long long
#define debug 0
const int mod=1e9+7;
//const int mod=998244353;
const int inf=1e9;
///check the limits, dummy
const int N=3e5+5;
int n;
int a[N*2];
int blue[N],red[N];
namespace sub2
{
void solve()
{
vector<int>b(2*n+1);
FOR(i,1,2*n)b[i]=a[i];
int ans=inf;
FOR(i,1,n+1)
{
sort(a+i,a+i+n);
int mx=0;
FOR(j,i,i+n-1)
{
mx=max(mx,abs(a[j]-blue[j-i+1]));
a[j]=b[j];
}
vector<int>v;
v.pb(0);
FOR(j,1,i-1)v.pb(a[j]);
FOR(j,i+n,2*n)v.pb(a[j]);
sort(all(v));
FOR(j,1,n)mx=max(mx,abs(v[j]-red[j]));
ans=min(ans,mx);
}
FOR(i,1,n+1)
{
sort(a+i,a+i+n);
int mx=0;
FOR(j,i,i+n-1)
{
mx=max(mx,abs(a[j]-blue[j-i+1]));
a[j]=b[j];
}
vector<int>v;
v.pb(0);
FOR(j,1,i-1)v.pb(a[j]);
FOR(j,i+n,2*n)v.pb(a[j]);
sort(all(v));
FOR(j,1,n)mx=max(mx,abs(v[j]-blue[j]));
ans=min(ans,mx);
}
cout<<ans;
exit(0);
}
}
namespace sub3
{
void solve()
{
}
}
die_hard_onimai_fan
{
cin>>n;
FOR(i,1,2*n)cin>>a[i];
FOR(i,1,n)cin>>red[i];
FOR(i,1,n)cin>>blue[i];
sort(red+1,red+n+1);
sort(blue+1,blue+n+1);
if(n<=3000)sub2::solve();
else sub3::solve();
}
__sumairu__
{
FAST
file("");
int tt=1;//cin>>tt;
while(tt--)seggs();
cerr<<"\nTime elapsed: "<<TIME<<" s.\n";
}
/**
2
1 2 6 3
2 5
4 3
*/
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:17:53: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
17 | #define file(name) if(fopen(name".inp","r")){freopen(name".inp","r",stdin);freopen(name".out","w",stdout);}
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
Main.cpp:132:5: note: in expansion of macro 'file'
132 | file("");
| ^~~~
Main.cpp:17:83: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
17 | #define file(name) if(fopen(name".inp","r")){freopen(name".inp","r",stdin);freopen(name".out","w",stdout);}
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:132:5: note: in expansion of macro 'file'
132 | file("");
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
121 ms |
11092 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |