-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathB600_CF.java
More file actions
43 lines (36 loc) · 1.22 KB
/
Copy pathB600_CF.java
File metadata and controls
43 lines (36 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import java.io.*;
import java.util.*;
public class B600_CF {
public static void main(String[] args) throws Exception {
BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st=new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());
int m = Integer.parseInt(st.nextToken());
long a[]= new long[n];
st=new StringTokenizer(br.readLine());
for(int i=0;i<n;i++)a[i]=Integer.parseInt(st.nextToken());
long b[]=new long[m];
st=new StringTokenizer(br.readLine());
for(int i=0;i<m;i++)b[i]=Integer.parseInt(st.nextToken());
Arrays.sort(a);
StringBuilder sb=new StringBuilder();
for(int i=0;i<m;i++){
long ans=binarySearch(0, n-1, a, b[i]);
sb.append(ans+1).append(" ");
}
System.out.println(sb.toString().trim());
}
public static long binarySearch(int low,int high,long a[],long b){
long ans=-1;
while(low<=high){
int mid=(low+high)/2;
if(a[mid]<=b){
ans=mid;
low=mid+1;
}else{
high=mid-1;
}
}
return ans;
}
}