tranhongquang191209
Giới thiệu
include<bits/stdc++.h>
using namespace std;
const int dd=2e5+7;
define int long long
int a[dd],b[dd],n,m,l,r;
int vt(int x)
{
l=1; r=n;
while(l<=r)
{
int mid=(l+r)/2;
if (a[mid]==x) return mid;
if (a[mid]>x) r=mid-1; else l=mid+1;
}
return -1;
}
void xuli()
{
cin>>n>>m;
for (int i=1; i<=n; ++i) cin>>a[i];
for (int i=1; i<=m; ++i) cin>>b[i];
sort(a+1,a+n+1);
for (int i=1; i<=m; ++i)
{
l=1; r=n; int kq=-2e9;
while(l<=r)
{
int mid=(l+r)/2;
if (a[mid]==b[i])
{
kq=a[mid];
break;
}
if (a[mid]<=b[i])
{
l=mid+1;
kq=max(kq,a[mid]);
} else if (a[mid]>b[i]) r=mid-1;
}
if (kq!=-2e9)
{
cout<<kq<<"\n";
if (vt(kq)!=-1) a[vt(kq)]=2e9;
} else cout<<"-1\n";
}
}
signed main()
{
ios::sync_with_stdio(0); cin.tie(0);
xuli();
}