Advertisement
Alexvans

Cola Bancaria

Jul 6th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.83 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define MAX 50002
  3. using namespace std;
  4.  
  5. int n, id;
  6. int acum[26];
  7. priority_queue<pair<int, pair<int, string> > > cola[26];
  8.  
  9. int main() {
  10.     ios_base::sync_with_stdio(0);
  11.     cin.tie(0);
  12.     cout.tie(0);
  13.    
  14.     memset(acum, 0, sizeof(acum));
  15.  
  16.     cin >> n;
  17.     for(int T = 0; T < n; T++) {
  18.         char op;
  19.         cin >> op;
  20.         if(op == 'C') {
  21.             int prioridad;
  22.             string nombre;
  23.             cin >> nombre >> prioridad;
  24.             int idx = nombre[0] - 65;
  25.             //pair <int, string> temp = make_pair(prioridad, nombre);
  26.             //cout << "acum: " << prioridad - acum[idx] << endl;
  27.             //cola[idx].push(make_pair(id, make_pair(prioridad-acum[idx], nombre)));
  28.             cola[idx].push(make_pair(prioridad-acum[idx], make_pair(id, nombre)));
  29.             id++;
  30.         }
  31.         else if(op == 'S') {
  32.             int sum;
  33.             char letra;
  34.             cin >> letra >> sum;
  35.             int idx = letra - 65;
  36.             acum[idx] += sum;
  37.             //cout << acum[idx] << " idx:" << idx << endl;
  38.         }
  39.         else if(op == 'A') {
  40.             int mayor = -(1<<30), index = 0;
  41.             string temp;
  42.             for(int i = 0; i < 26; i++) {
  43.                 if(!cola[i].empty()){
  44.                     if(cola[i].top().first + acum[i] > mayor) {
  45.                         mayor = cola[i].top().first + acum[i];
  46.                         temp = cola[i].top().second.second;
  47.                         index = i;
  48.                     }
  49.                     else if(cola[i].top().first + acum[i] == mayor) {
  50.                         if(cola[i].top().second.first < cola[index].top().second.first) {
  51.                             temp = cola[i].top().second.second;
  52.                             index = i;
  53.                         }
  54.                     }
  55.                 }
  56.             }
  57.             cout << cola[index].top().second.second << "\n";
  58.             cola[index].pop();
  59.         }
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement