直接上代码
//http://ybt.soccer:8088/problem_show.php?pid=1240
//http://t.csdn.cn/8rD42
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,m;
long long a[n],b;
void find(int left ,int right){
if(right-left==1){
if(b-a[left]<=a[right]-b){
cout<<a[left]<<"\n";
return ;
}else{
cout<<a[right]<<"\n";
return ;
}
}
int mid=(l+r)/2;
if(a[mid]==b) cout<<b<<"\n";
else if(a[mid]<b) find(mid,right);
else find(left,mid);
}
int main(){
cin>>n>>m;
for(int i=0;i<n;i++){
cin>>a[i];
}
sort(a,a+n);
for(int i=0;i<m;i++){
cin>>b;
if(a[n-1]<b) cout<<a[n-1]<<"\n";
else if(a[0]>b) cout<<a[0]<<"\n";
else find(0,n);
}
return 0;
}