File tree Expand file tree Collapse file tree 1 file changed +62
-0
lines changed
Expand file tree Collapse file tree 1 file changed +62
-0
lines changed Original file line number Diff line number Diff line change 1+ ``` java
2+ import java.io.* ;
3+ import java.util.PriorityQueue ;
4+ import java.util.Queue ;
5+ import java.util.StringTokenizer ;
6+
7+ public class BJ_2696_ 중앙값_구하기 {
8+
9+ private static final BufferedReader br = new BufferedReader (new InputStreamReader (System . in));
10+ private static final BufferedWriter bw = new BufferedWriter (new OutputStreamWriter (System . out));
11+ private static StringTokenizer st;
12+
13+ private static int T ;
14+ private static int M ;
15+ private static String s;
16+
17+ private static Queue<Integer > minq;
18+ private static Queue<Integer > maxq;
19+
20+ public static void main (String [] args ) throws IOException {
21+ sol();
22+ }
23+
24+ private static void sol () throws IOException {
25+ T = Integer . parseInt(br. readLine());
26+
27+ while (T -- > 0 ) {
28+ M = Integer . parseInt(br. readLine());
29+
30+ s = " " ;
31+ minq = new PriorityQueue<> ();
32+ maxq = new PriorityQueue<> ((a, b) - > b - a);
33+ for (int i = 0 ; i < M ; i++ ) {
34+ if (i % 10 == 0 ) {
35+ st = new StringTokenizer (br. readLine());
36+ }
37+
38+ if (i % 2 == 0 ) {
39+ maxq. offer(Integer . parseInt(st. nextToken()));
40+ } else {
41+ minq. offer(Integer . parseInt(st. nextToken()));
42+ }
43+
44+ if (! minq. isEmpty() && maxq. peek() > minq. peek()) {
45+ minq. offer(maxq. poll());
46+ maxq. offer(minq. poll());
47+ }
48+
49+ if (i % 2 == 0 ) {
50+ s += maxq. peek() + (i > 2 && (i + 2 ) % 20 == 0 ? " \n " : " " );
51+ }
52+ }
53+ bw. write(maxq. size() + " \n " );
54+ bw. write(s + " \n " );
55+ }
56+ bw. flush();
57+ bw. close();
58+ br. close();
59+ }
60+
61+ }
62+ ```
You can’t perform that action at this time.
0 commit comments