Advertisement
Guest User

Untitled

a guest
May 1st, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.69 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. #include <cstdlib>
  4. #include <cstdio>
  5. #include <cmath>
  6. #include <vector>
  7. #include <algorithm>
  8. #include <map>
  9. #include <set>
  10. #include <queue>
  11. #include <string>
  12. using namespace std;
  13.  
  14. const int MAXN = 20005;
  15.  
  16. int tm[MAXN], cnt[MAXN];
  17. char s[MAXN];
  18. set<pair<int, int> > st;
  19. int last[MAXN];
  20. int pas[MAXN];
  21. int tp[MAXN];
  22. int sz = 0;
  23.  
  24. int main() {
  25.   freopen("a.in", "r", stdin);
  26.   //freopen("a.out", "w", stdout);
  27.  
  28.   int k, n;
  29.   scanf("%d%d", &k, &n);
  30.   for (int i = 0; i < n; i++) {
  31.     scanf("%d%d", &tm[i], &cnt[i]);
  32.   }
  33.   int crit = min(5, k / 5);
  34.   while(true) {
  35.     while(true) {
  36.       int p;
  37.       scanf("%d", &p);
  38.       if (feof(stdin))
  39.         return 0;
  40.       if (p == -1)
  41.         break;
  42.       tp[sz] = p;
  43.       last[sz] = cnt[p];
  44.       st.insert({last[sz], sz});
  45.       sz ++;
  46.     }
  47.     while(true) {
  48.       int id, te;
  49.       scanf("%d%d", &id, &te);
  50.       if (feof(stdin))
  51.         return 0;
  52.       if (id < 0)
  53.         break;
  54.       k++;
  55.       scanf("%s", s);
  56.       if (s[0] == 'O') {
  57.         pas[id] ++;
  58.       } else {
  59.         pas[id] = cnt[tp[id]];
  60.       }
  61.       if (pas[id] == cnt[tp[id]]) {
  62.         if (last[id] > 0)
  63.           st.erase({last[id], id});
  64.       }
  65.     }
  66.     while(st.size() > 0 && k > crit) {
  67.       pair<int, int> p = *st.begin();
  68.       int id = p.second;
  69.       st.erase({last[id], id});
  70.       int rem = min(last[id], k);
  71.       if (rem < last[id])
  72.         rem = k - crit;
  73.       for (int i = 0; i < rem; i++)
  74.         printf("%d %d\n", id, last[id] - 1), last[id]--, k--;
  75.       if (last[id] > 0)
  76.         st.insert({last[id], id});
  77.     }
  78.     printf("-1 -1\n");
  79.     fflush(stdout);
  80.   }
  81.  
  82.   return 0;
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement