File tree Expand file tree Collapse file tree 1 file changed +50
-0
lines changed
Expand file tree Collapse file tree 1 file changed +50
-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+ static BufferedReader br = new BufferedReader (new InputStreamReader (System . in));
7+ static BufferedWriter bw = new BufferedWriter (new OutputStreamWriter (System . out));
8+ static StringTokenizer st;
9+ static int N ,H ;
10+
11+ public static void main (String [] args ) throws IOException {
12+ st = new StringTokenizer (br. readLine());
13+ N = Integer . parseInt(st. nextToken());
14+ H = Integer . parseInt(st. nextToken());
15+
16+ int [] top = new int [H + 1 ];
17+ int [] bot = new int [H + 1 ];
18+ for (int i = 0 ; i < N ; i++ ) {
19+ int cur = Integer . parseInt(br. readLine());
20+ if (i% 2 == 0 ){
21+ bot[cur]++ ;
22+ }else {
23+ top[cur]++ ;
24+ }
25+ }
26+
27+ for (int i = H - 1 ; i > 1 ; i-- ) {
28+ bot[i- 1 ] += bot[i];
29+ }
30+ for (int i = H - 1 ; i > 1 ; i-- ) {
31+ top[i- 1 ] += top[i];
32+ }
33+
34+ int min = N ;
35+ int cnt = 0 ;
36+ for (int i = 1 ; i <= H ; i++ ) {
37+ int cur = top[H - i+ 1 ] + bot[i];
38+ if (min == cur){
39+ cnt++ ;
40+ }else if (min > cur){
41+ min = cur;
42+ cnt = 1 ;
43+ }
44+ }
45+
46+ bw. write(min+ " " + cnt);
47+ bw. close();
48+ }
49+ }
50+ ```
You can’t perform that action at this time.
0 commit comments