Skip to content

Instantly share code, notes, and snippets.

@eddy1021
Created November 9, 2015 03:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eddy1021/f6cfeb829e7a7892ab2b to your computer and use it in GitHub Desktop.
Save eddy1021/f6cfeb829e7a7892ab2b to your computer and use it in GitHub Desktop.
// eddy1021
#include <bits/stdc++.h>
using namespace std;
typedef double D;
typedef long long ll;
typedef pair<int,int> PII;
#define mod9 1000000009ll
#define mod7 1000000007ll
#define INF 1023456789ll
#define INF16 10000000000000000ll
#define FI first
#define SE second
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define eps 1e-9
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(), (x).end()
ll getint(){
ll _x=0,_tmp=1; char _tc=getchar();
while( (_tc<'0'||_tc>'9')&&_tc!='-' ) _tc=getchar();
if( _tc == '-' ) _tc=getchar() , _tmp = -1;
while(_tc>='0'&&_tc<='9') _x*=10,_x+=(_tc-'0'),_tc=getchar();
return _x*_tmp;
}
ll mypow( ll _a , ll _x , ll _mod ){
if( _x == 0 ) return 1ll;
ll _tmp = mypow( _a , _x / 2 , _mod );
_tmp = ( _tmp * _tmp ) % _mod;
if( _x & 1 ) _tmp = ( _tmp * _a ) % _mod;
return _tmp;
}
bool equal( D _x , D _y ){
return _x > _y - eps && _x < _y + eps;
}
int __ = 1 , cs;
/*********default*********/
#define N 514514
int n , a[ N ] , tk;
void build(){
}
void init(){
n = getint(); tk = ( n - 2 ) / 2;
for( int i = 0 ; i < n ; i ++ )
a[ i ] = getint();
sort( a , a + n );
}
bool okay( int dlt ){
int pre = a[ 0 ] , bn = 0;
for( int i = 1 ; i < n ; i ++ )
if( a[ i ] - pre < dlt ) bn ++;
else pre = a[ i ];
return bn <= tk;
}
void solve(){
int l = 1 , r = a[ n - 1 ] - a[ 0 ], mid, ans = 1;
while( l <= r ){
mid = ( l + r ) >> 1;
if( okay( mid ) ) ans = mid, l = mid + 1;
else r = mid - 1;
}
printf( "%d\n" , ans );
}
int main(){
build();
//__ = getint();
while( __ -- ){
init();
solve();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment