fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. queue <pair <int, int> > cars[2];
  4. long long tmes[10005];
  5. long long tme,inp_tme,n,t,m,c,po,carsloaded;
  6. string dum;
  7. int main()
  8. {
  9. cin.sync_with_stdio(0);
  10. cin.tie(0);
  11. cin >> c;
  12. while (c--) {
  13. cin >> n >> t >> m;
  14. for (int i=0;i<m;++i) {
  15. cin >> inp_tme >> dum;
  16. if (dum=="left") cars[0].push(make_pair(inp_tme,i));
  17. else cars[1].push(make_pair(inp_tme,i));
  18. }
  19. tme=0;
  20. po=0;
  21. carsloaded=0;
  22. while (!cars[0].empty() || !cars[1].empty()) {
  23. carsloaded=0;
  24. if (!cars[po].empty()) {
  25. if (cars[po].front().first > tme) {
  26. if (!cars[(po+1)&1].empty() && (cars[po].front().first > cars[(po+1)&1].front().first)) {
  27. tme=cars[(po+1)&1].front().first;
  28. po=(po+1)&1;
  29. tme+=t;
  30. continue;
  31. }
  32. else tme=cars[po].front().first;
  33. }
  34. while ((carsloaded < n) && !cars[po].empty() && (cars[po].front().first <= tme)) { ++carsloaded; tmes[cars[po].front().second]=tme+t; cars[po].pop(); }
  35. }
  36. tme+=t;
  37. po=(po+1)&1;
  38. }
  39. for (int i=0;i<m;++i) cout << tmes[i] << '\n';
  40. if (c>0) cout << '\n';
  41. }
  42. return 0;
  43. }
  44.  
Success #stdin #stdout 0s 3304KB
stdin
2
2 10 10
0 left
10 left
20 left
30 left
40 left
50 left
60 left
70 left
80 left
90 left
2 10 3
10 right
25 left
40 left
stdout
10
30
30
50
50
70
70
90
90
110

30
40
60