-
Notifications
You must be signed in to change notification settings - Fork 0
/
doctor_kattis.cpp
106 lines (80 loc) · 2.17 KB
/
doctor_kattis.cpp
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<unordered_set>
#include<cmath>
#include<climits>
#include<queue>
#include<map>
#include<unordered_map>
#define FOR(i,a,b) for(int i = a; i < b; i++)
#define FORD(i,a,b) for(int i = b; i >= a; i--)
#define FORE(i,a,b) for(int i = a; i <=b; i++)
#define SIZE(x) x.size()
#define vi vector<int>
#define usi unordered_set<int>
#define si set<int>
using namespace std;
struct cat{
int arival;
int iLvl;
string name;
bool operator < (const cat & c) const{
if(iLvl != c.iLvl){
return iLvl > c.iLvl;
}
return arival < c.arival;
}
};
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, comand, iLvl;
int totalCat = 0;
string name;
cat c;
cin >> n;
set<cat> allCats;
map<string, pair<int, int>> old;
FOR(i,0,n){
cin >> comand;
if (comand == 0){
cin >> name >> iLvl;
c.arival = totalCat;
c.iLvl = iLvl;
c.name = name;
allCats.insert(c);
old[name] = {totalCat, iLvl};
totalCat++;
}
else if(comand == 1){
cin >> name >> iLvl;
c.name = name;
c.iLvl = old.at(name).second;
c.arival = old.at(name).first;
auto it = allCats.find(c); //find this cat in the set
auto oldCat = *it; //get its content by de reference
allCats.erase(it); //make it go bye bye
oldCat.iLvl += iLvl;
allCats.insert(oldCat); //insert the new boi
old.at(name).second = oldCat.iLvl; //update the map
}
else if(comand == 2){
cin >> name;
c.name = name;
c.arival = old.at(name).first;
c.iLvl = old.at(name).second;
allCats.erase(allCats.find(c));
}
else{
if(allCats.empty()){
cout << "The clinic is empty\n";
}
else{
cout << (*allCats.begin()).name << endl;
}
}
}
return 0;
}