Skip to content

Commit 36da3b9

Browse files
committed
feat(codeforces): implement solution for p2189A
1 parent 3f12c16 commit 36da3b9

1 file changed

Lines changed: 38 additions & 30 deletions

File tree

  • src/main/java/com/lzw/solutions/codeforces/p2189A
Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,49 @@
11
package com.lzw.solutions.codeforces.p2189A;
22

3-
import java.io.BufferedReader;
4-
import java.io.IOException;
5-
import java.io.InputStreamReader;
6-
import java.io.PrintWriter;
3+
import java.io.*;
4+
import java.util.*;
75

86
public class Main {
9-
private static final BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
10-
private static final PrintWriter out = new PrintWriter(System.out, true);
11-
12-
private static void solve() throws IOException {
13-
String[] first = in.readLine().split(" ");
14-
int n = Integer.parseInt(first[0]);
15-
int h = Integer.parseInt(first[1]);
16-
int l = Integer.parseInt(first[2]);
17-
18-
String[] line = in.readLine().split(" ");
19-
int cntRow = 0;
20-
int cntCol = 0;
21-
22-
for (String s : line) {
23-
int x = Integer.parseInt(s);
24-
if (x <= h) cntRow++;
25-
if (x <= l) cntCol++;
26-
}
27-
28-
int maxPairs = Math.min(cntRow, cntCol);
29-
maxPairs = Math.min(maxPairs, n / 2);
7+
public static void main(String[] args) throws IOException {
8+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
9+
PrintWriter out = new PrintWriter(System.out);
3010

31-
out.println(maxPairs);
32-
}
11+
int t = Integer.parseInt(br.readLine().trim());
3312

34-
public static void main(String[] args) throws IOException {
35-
int t = Integer.parseInt(in.readLine());
3613
while (t-- > 0) {
37-
solve();
14+
StringTokenizer st = new StringTokenizer(br.readLine());
15+
int n = Integer.parseInt(st.nextToken());
16+
int h = Integer.parseInt(st.nextToken());
17+
int l = Integer.parseInt(st.nextToken());
18+
19+
int minHL = Math.min(h, l);
20+
21+
int cntRow = 0;
22+
int cntCol = 0;
23+
int cntBoth = 0;
24+
25+
st = new StringTokenizer(br.readLine());
26+
while (st.hasMoreTokens()) {
27+
int x = Integer.parseInt(st.nextToken());
28+
if (x <= minHL) {
29+
cntBoth++;
30+
cntRow++;
31+
cntCol++;
32+
} else if (x <= h) {
33+
cntRow++;
34+
} else if (x <= l) {
35+
cntCol++;
36+
}
37+
}
38+
39+
int usable = cntRow + cntCol - cntBoth;
40+
int ans = usable / 2;
41+
ans = Math.min(ans, cntRow);
42+
ans = Math.min(ans, cntCol);
43+
44+
out.println(ans);
3845
}
46+
3947
out.close();
4048
}
4149
}

0 commit comments

Comments
 (0)