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