fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define ll long long
  6.  
  7. #define EGRY \
  8.   ios_base::sync_with_stdio(false); \
  9.   cin.tie(NULL);
  10.  
  11. const int MAX = 1e6 + 100;
  12.  
  13. /*
  14.  
  15.   yaaaaaaaaaaaaaaaaaaaaaaaaaaaayyyyyyyyy
  16.  
  17. */
  18.  
  19. bool is_left(string &str)
  20. {
  21. return (str == "left");
  22. }
  23.  
  24. bool is_right(string &str)
  25. {
  26. return (str == "right");
  27. }
  28.  
  29. void solve()
  30. {
  31. ll l, n;
  32. cin >> l >> n;
  33. l *= 100;
  34.  
  35. bool left = true;
  36. ll res = 0;
  37.  
  38. queue<pair<ll, string>> leftCars;
  39. queue<pair<ll, string>> rightCars;
  40.  
  41. while (n--)
  42. {
  43. ll meter;
  44. string dir;
  45. cin >> meter >> dir;
  46. if (is_left(dir))
  47. {
  48. leftCars.push({meter, dir});
  49. }
  50. else
  51. {
  52. rightCars.push({meter, dir});
  53. }
  54. }
  55.  
  56. while (!leftCars.empty() || !rightCars.empty())
  57. {
  58. if (left)
  59. {
  60. ll sum = 0;
  61. while (sum <= l && !leftCars.empty())
  62. {
  63. sum += leftCars.front().first;
  64. if (sum > l)
  65. {
  66. break;
  67. }
  68. leftCars.pop();
  69. }
  70. }
  71. else
  72. {
  73. ll sum = 0;
  74. while (sum <= l && !rightCars.empty())
  75. {
  76. sum += rightCars.front().first;
  77. if (sum > l)
  78. {
  79. break;
  80. }
  81. rightCars.pop();
  82. }
  83. }
  84. left = !left;
  85. res++;
  86. }
  87.  
  88. cout << res << endl;
  89. }
  90.  
  91. int main()
  92. {
  93. EGRY int t = 1;
  94. cin >> t;
  95.  
  96. while (t--)
  97. {
  98. solve();
  99. }
  100.  
  101. return 0;
  102. }
Success #stdin #stdout 0.01s 5284KB
stdin
Standard input is empty
stdout
0