2856: 小A的游戏制作系列一
二分查找lower_bound的使用
#include<iostream>
#include<algorithm>
using namespace std;
const int N = 1000010;
int n,m;
int a[N];
signed main()
{
scanf("%d%d",&n,&m);
for(int i=0;i<n;i++) scanf("%d",&a[i]);
sort(a,a+n);
reverse(a,a+n);
while(m--)
{
int x;scanf("%d",&x);
int pos=*lower_bound(a,a+n,x,greater<int>());//二分查找//在数据库里小于等于x的最大数值
if(pos==0) printf("%d\n",a[0]);//找不到比它小的
else printf("%d\n",pos);
}
return 0;
}