Guest User

Untitled

a guest
Oct 18th, 2011
630
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <cstdio>
  2. #include <cstdlib>
  3. #include <cstring>
  4. #include <cmath>
  5. #include <cassert>
  6. #include <algorithm>
  7. #include <string>
  8. #include <vector>
  9. #include <deque>
  10.  
  11. using namespace std;
  12.  
  13. #define eprintf(...) fprintf(stderr, __VA_ARGS__)
  14. #define pb push_back
  15. #define mp make_pair
  16. #define sz(x) ((int)(x).size())
  17.  
  18. typedef long long ll;
  19. typedef vector<ll> vll;
  20. typedef vector<int> vi;
  21. typedef vector<vi> vvi;
  22. typedef vector<bool> vb;
  23. typedef vector<vb> vvb;
  24. typedef pair<int, int> pii;
  25.  
  26. int main() {
  27.   #ifdef DEBUG
  28.   freopen("std.in", "r", stdin);
  29.   freopen("std.out", "w", stdout);
  30.   #else
  31.   freopen("input.txt", "r", stdin);
  32.   freopen("output.txt", "w", stdout);
  33.   #endif
  34.  
  35.   int n, t;
  36.   while (scanf("%d%d", &n, &t) >= 2) {
  37.     vvi as(n, vi(2)), bs(n, vi(2));
  38.     for (int i = 0; i < n; i++)
  39.       for (int i2 = 0; i2 < 2; i2++)
  40.         scanf("%d%d", &as[i][i2], &bs[i][i2]);
  41.  
  42.     int m;
  43.     scanf("%d", &m);
  44.     vector<string> ns(m); vi cs(m);
  45.     for (int i = 0; i < m; i++) {
  46.       char buf[30];
  47.       scanf("%s%d", buf, &cs[i]);
  48.       ns[i] = buf;
  49.     }
  50.  
  51.     vector<vector<string> > res(n);
  52.  
  53.     vvi d(n, vi(m, 0));
  54.     deque<int> dq;
  55.     for (int i = 0; i < m; i++) dq.pb(i);
  56.  
  57.     int cur = 0, cpl = 0;
  58.     while (!dq.empty()) {
  59.       int curt = t;
  60.       while (curt > 0 && !dq.empty()) {
  61.         int card = dq.front(); dq.pop_front();
  62.         int need = max(1, cs[card] - (as[cur][cpl] + bs[cur][!cpl]) - d[cur][card]);
  63.         if (curt >= need) {
  64.           curt -= need;
  65.           res[cur].pb(ns[card]);
  66.         } else {
  67.           dq.pb(card);
  68.           d[cur][card] += curt;
  69.           curt = 0;
  70.         }
  71.       }
  72.  
  73.       if (++cur >= n) {
  74.         cur = 0;
  75.         cpl = !cpl;
  76.       }
  77.     }
  78.     for (int i = 0; i < n; i++) {
  79.       printf("%d", sz(res[i]));
  80.       for (int i2 = 0; i2 < sz(res[i]); i2++)
  81.         printf(" %s", res[i][i2].c_str());
  82.       printf("\n");
  83.     }
  84.   }
  85.   return 0;
  86. }
  87.  
  88.  
RAW Paste Data