Skip to content

Commit b59a8a8

Browse files
authored
Merge pull request #1112 from AlgorithmWithGod/JHLEE325
[20251014] BOJ / G5 / 개똥벌레 / 이준희
2 parents 51636f9 + 8481f2a commit b59a8a8

File tree

1 file changed

+43
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)