Skip to content

Commit 85c20b2

Browse files
authored
[20250825] BOJ / G5 / 개똥벌레 / 김수연
1 parent 36b71e1 commit 85c20b2

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
```java
2+
import java.util.*;
3+
import java.io.*;
4+
5+
public class boj3020 {
6+
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
7+
static StringTokenizer st;
8+
static void nextLine() throws Exception {st = new StringTokenizer(br.readLine());}
9+
static int nextInt() {return Integer.parseInt(st.nextToken());}
10+
11+
public static void main(String[] args) throws Exception {
12+
nextLine();
13+
int N = nextInt();
14+
int H = nextInt();
15+
16+
int[] A = new int[H + 1];
17+
int[] B = new int[H + 1];
18+
19+
for (int n = 0; n < N; n += 2) {
20+
nextLine();
21+
A[nextInt()]++;
22+
nextLine();
23+
B[nextInt()]++;
24+
}
25+
26+
for (int h = H - 1; 0 < h; h--) {
27+
A[h] += A[h + 1];
28+
B[h] += B[h + 1];
29+
}
30+
31+
int count = 0;
32+
int min = N;
33+
34+
for (int h = H; 0 < h; h--) {
35+
if (A[h] + B[H - h + 1] < min) {
36+
count = 1;
37+
min = A[h] + B[H - h + 1];
38+
} else if (A[h] + B[H - h + 1] == min) {
39+
count++;
40+
}
41+
}
42+
System.out.println(min + " " + count);
43+
}
44+
}
45+
```

0 commit comments

Comments
 (0)