标签:char solution reg namespace efi sort ble lib ret
#include<iostream>
#include<cstdio>
#include<iomanip>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<ctime>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<set>
#define ll long long
#define db double
#define inf 0x7fffffff
#define rg register int
using namespace std;
int n,m,k,ans;
int a[50005];
inline int qr(){
char ch;
while((ch=getchar())<'0'||ch>'9');
int res=ch^48;
while((ch=getchar())>='0'&&ch<='9')
res=res*10+(ch^48);
return res;
}
inline bool check(ll x,int k){
int tot=0;
for(rg i=1,j=2;i<=n;++i){
while(a[j]-a[i]<=x&&j<=n)++j;
tot+=j-i-1;
}
return tot<k?0:1;
}
inline int fen(int k){
ll l=1,r=inf,mid;
while(l<=r){
mid=(l+r)>>1;
if(check(mid,k))r=mid-1;
else l=mid+1;
}return l;
}
int main(){
freopen("game.in","r",stdin);
freopen("game.out","w",stdout);
n=qr(); m=(ll)n*(n-1)/2;
for(rg i=1;i<=n;++i)a[i]=qr();
sort(a+1,a+n+1);
ans=fen(m/2+1);
if(!(m&1))ans=((ll)ans+(ll)fen(m/2))/2;
printf("%d\n",ans);
return 0;
}
标签:char solution reg namespace efi sort ble lib ret
原文地址:https://www.cnblogs.com/812-xiao-wen/p/10363209.html