Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathBOJ_7662.java
More file actions
Latest commit
53 lines (46 loc) · 1.38 KB
/
Copy pathBOJ_7662.java
File metadata and controls
53 lines (46 loc) · 1.38 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
42
43
44
45
46
47
48
49
50
51
52
53
packagealgorithm_study.april.day_04_16;
importjava.io.BufferedReader;
importjava.io.IOException;
importjava.io.InputStreamReader;
importjava.util.Comparator;
importjava.util.StringTokenizer;
importjava.util.TreeSet;
publicclassBOJ_7662 {
publicstaticvoidmain(String[] args) throwsNumberFormatException, IOException {
BufferedReaderbr = newBufferedReader(newInputStreamReader(System.in));
StringTokenizerst = null;
TreeSet<Integer> ts = newTreeSet<>(newComparator<Integer>() {
@Override
publicintcompare(Integero1, Integero2) {
returno1 > o2 ? 1 : -1;
}
});
intTC = Integer.parseInt(br.readLine());
for (inttc = 1; tc <= TC; tc++) {
intk = Integer.parseInt(br.readLine());
for (inti = 0; i < k; i++) {
st = newStringTokenizer(br.readLine());
charcommand = st.nextToken().charAt(0);
intvalue = Integer.parseInt(st.nextToken());
if(command == 'I') {
ts.add(value);
} elseif(command == 'D') {
if(value == 1) {
ts.pollLast();
} else {
ts.pollFirst();
}
}
}
if(ts.size() == 0) {
System.out.println("EMPTY");
} elseif(ts.size() == 1) {
intresult = ts.first();
System.out.println(result + " " + result);
} else {
System.out.println(ts.pollLast() + " " + ts.pollFirst());
}
ts.clear();
}
}
}