-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBima1.java
74 lines (62 loc) · 1.61 KB
/
Bima1.java
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package hiring.contest;
import java.util.*;
public class Bima1 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner s=new Scanner(System.in);
int q=s.nextInt();
Map<Integer, Integer> prio=new HashMap<>();
SortedSet<Request> set1=new TreeSet<>(new Comparator<Request>() {
@Override
public int compare(Request a, Request b) {
return a.time.compareTo(b.time);
}
});
SortedSet<Request> set2=new TreeSet<>(new Comparator<Request>() {
@Override
public int compare(Request a, Request b) {
return a.priority.compareTo(b.priority);
}
});
while(q--!=0) {
int type=s.nextInt();
switch(type) {
case 1: {
int time=s.nextInt(), priority=s.nextInt();
if(prio.containsKey(time)) {
set1.remove(new Request(time, prio.get(time)));
set2.remove(new Request(time, prio.get(time)));
}
set1.add(new Request(time, priority));
set2.add(new Request(time, priority));
prio.put(time, priority);
break;
}
case 2: {
int time=s.nextInt();
if(prio.containsKey(time)) {
set1.remove(new Request(time, prio.get(time)));
set2.remove(new Request(time, prio.get(time)));
prio.remove(time);
}
break;
}
case 3: {
System.out.println(set2.first().priority + " " + set2.last().priority);
break;
}
case 4: {
System.out.println(set1.last().priority);
break;
}
}
}
}
}
class Request {
Integer time, priority;
Request(int t, int p) {
time=t;
priority=p;
}
}