# Educational Codeforces Round 2 B.Queries about less or equal elements(排序&&二分)

Educational Codeforces Round 2B：http://codeforces.com/contest/600/problem/B

B. Queries about less or equal elements
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given two arrays of integers a and b. For each element of the second array bj you should find the number of elements in arraya that are less than or equal to the value bj.

Input

The first line contains two integers n, m (1 ≤ n, m ≤ 2·105) — the sizes of arrays a and b.

The second line contains n integers — the elements of array a ( - 109 ≤ ai ≤ 109).

The third line contains m integers — the elements of array b ( - 109 ≤ bj ≤ 109).

Output

Print m integers, separated by spaces: the j-th of which is equal to the number of such elements in array a that are less than or equal to the value bj.

Sample test(s)
input
5 4
1 3 5 7 9
6 4 2 8

output
3 2 1 4

input
5 5
1 2 1 2 5
3 1 4 1 5

output
4 2 4 2 5

#include <cstdio>
#include <algorithm>

using namespace std;

int a,n,m,i,b;

int main() {
while(2==scanf("%d%d",&n,&m)) {
for(i=0;i<n;++i)
scanf("%d",a+i);
sort(a,a+n);
a[n++]=0x3f3f3f3f;
scanf("%d",&b);
printf("%d",upper_bound(a,a+n,b)-a);
while(--m) {
scanf("%d",&b);
printf(" %d",upper_bound(a,a+n,b)-a);
}
printf("\n");
}
return 0;
}


©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客 