Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions Seol-JY/202507/15 G4 7662 이중 우선순위 큐.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
```java
import java.io.*;
import java.util.*;

public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();

int T = Integer.parseInt(br.readLine());

while (T-- > 0) {
TreeMap<Integer, Integer> map = new TreeMap<>();
int k = Integer.parseInt(br.readLine());

for (int i = 0; i < k; i++) {
StringTokenizer st = new StringTokenizer(br.readLine());
String op = st.nextToken();
int n = Integer.parseInt(st.nextToken());

if (op.equals("I")) {
map.put(n, map.getOrDefault(n, 0) + 1);
continue;
}

if (map.isEmpty()) continue;

int key = (n == 1) ? map.lastKey() : map.firstKey();
if (map.get(key) == 1) {
map.remove(key);
} else {
map.put(key, map.get(key) - 1);
}
}

if (map.isEmpty()) {
sb.append("EMPTY\n");
} else {
sb.append(map.lastKey()).append(" ").append(map.firstKey()).append("\n");
}
}

System.out.print(sb);
}
}
```