File tree Expand file tree Collapse file tree 1 file changed +43
-0
lines changed
Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change 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+ ```
You can’t perform that action at this time.
0 commit comments