-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path3020.java
More file actions
41 lines (34 loc) · 1.13 KB
/
3020.java
File metadata and controls
41 lines (34 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] input = br.readLine().split(" ");
int N = Integer.parseInt(input[0]);
int H = Integer.parseInt(input[1]);
int[] top = new int[H + 1];
int[] bottom = new int[H + 1];
for(int i = 0; i < N; i++) {
int len = Integer.parseInt(br.readLine());
if(i % 2 == 0) bottom[len]++;
else top[len]++;
}
br.close();
for(int i = H - 1; i > 0; i--) {
top[i] += top[i + 1];
bottom[i] += bottom[i + 1];
}
int min = Integer.MAX_VALUE;
int answer = 0;
for(int i = 1; i <= H; i++) {
int count = top[i] + bottom[H - i + 1];
if(min > count) {
min = count;
answer = 1;
}
else if(min == count) answer++;
}
System.out.println(min + " " + answer);
}
}