-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathp7795.java
More file actions
58 lines (50 loc) · 1.57 KB
/
p7795.java
File metadata and controls
58 lines (50 loc) · 1.57 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
먹을 것인가 먹힐 것인가
이분탐색
*/
import java.io.*;
import java.util.*;
public class p7795 {
static int t;
static int n, m;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;
t = Integer.parseInt(br.readLine());
while(t-- > 0) {
st = new StringTokenizer(br.readLine());
n = Integer.parseInt(st.nextToken());
m = Integer.parseInt(st.nextToken());
int[] a = new int[n + 1];
int[] b = new int[m + 1];
st = new StringTokenizer(br.readLine());
for (int i = 1; i <= n; i++) {
a[i] = Integer.parseInt(st.nextToken());
}
st = new StringTokenizer(br.readLine());
for (int i = 1; i <= m; i++) {
b[i] = Integer.parseInt(st.nextToken());
}
Arrays.sort(b, 1, m + 1);
int ans = 0;
for (int i = 1; i <= n; i++) {
ans += solution(b, 1, m, a[i]);
}
System.out.println(ans);
}
}
// target보다 작은 게 몇개 있는지 카운트 해서 리턴
static int solution(int[] arr, int l, int r, int target) {
int ret = l - 1;
while (l <= r) {
int mid = (l + r) / 2;
if (arr[mid] < target) {
ret = mid;
l = mid + 1;
} else {
r = mid - 1;
}
}
return ret;
}
}