Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define MAX 50002
- using namespace std;
- int n, id;
- int acum[26];
- priority_queue<pair<int, pair<int, string> > > cola[26];
- int main() {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- memset(acum, 0, sizeof(acum));
- cin >> n;
- for(int T = 0; T < n; T++) {
- char op;
- cin >> op;
- if(op == 'C') {
- int prioridad;
- string nombre;
- cin >> nombre >> prioridad;
- int idx = nombre[0] - 65;
- //pair <int, string> temp = make_pair(prioridad, nombre);
- //cout << "acum: " << prioridad - acum[idx] << endl;
- //cola[idx].push(make_pair(id, make_pair(prioridad-acum[idx], nombre)));
- cola[idx].push(make_pair(prioridad-acum[idx], make_pair(id, nombre)));
- id++;
- }
- else if(op == 'S') {
- int sum;
- char letra;
- cin >> letra >> sum;
- int idx = letra - 65;
- acum[idx] += sum;
- //cout << acum[idx] << " idx:" << idx << endl;
- }
- else if(op == 'A') {
- int mayor = -(1<<30), index = 0;
- string temp;
- for(int i = 0; i < 26; i++) {
- if(!cola[i].empty()){
- if(cola[i].top().first + acum[i] > mayor) {
- mayor = cola[i].top().first + acum[i];
- temp = cola[i].top().second.second;
- index = i;
- }
- else if(cola[i].top().first + acum[i] == mayor) {
- if(cola[i].top().second.first < cola[index].top().second.first) {
- temp = cola[i].top().second.second;
- index = i;
- }
- }
- }
- }
- cout << cola[index].top().second.second << "\n";
- cola[index].pop();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement