Skip to content

Commit dc9fc23

Browse files
authored
Merge pull request #2025 from AlgorithmWithGod/JHLEE325
[20260316] BOJ / G4 / 사냥꾼 / 이준희
2 parents 5c56d68 + 57bcc5c commit dc9fc23

1 file changed

Lines changed: 54 additions & 0 deletions

File tree

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
```java
2+
import java.io.*;
3+
import java.util.*;
4+
5+
public class Main {
6+
public static void main(String[] args) throws Exception {
7+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
8+
StringTokenizer st = new StringTokenizer(br.readLine());
9+
10+
int M = Integer.parseInt(st.nextToken());
11+
int N = Integer.parseInt(st.nextToken());
12+
int L = Integer.parseInt(st.nextToken());
13+
14+
int[] guns = new int[M];
15+
st = new StringTokenizer(br.readLine());
16+
for (int i = 0; i < M; i++) {
17+
guns[i] = Integer.parseInt(st.nextToken());
18+
}
19+
20+
Arrays.sort(guns);
21+
22+
int count = 0;
23+
for (int i = 0; i < N; i++) {
24+
st = new StringTokenizer(br.readLine());
25+
int x = Integer.parseInt(st.nextToken());
26+
int y = Integer.parseInt(st.nextToken());
27+
28+
if (y > L) continue;
29+
30+
int low = 0;
31+
int high = M - 1;
32+
33+
while (low <= high) {
34+
int mid = (low + high) / 2;
35+
36+
long dist = (long) Math.abs(guns[mid] - x) + y;
37+
38+
if (dist <= L) {
39+
count++;
40+
break;
41+
}
42+
43+
if (guns[mid] < x) {
44+
low = mid + 1;
45+
} else {
46+
high = mid - 1;
47+
}
48+
}
49+
}
50+
51+
System.out.println(count);
52+
}
53+
}
54+
```

0 commit comments

Comments
 (0)