-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path11034.cpp
More file actions
37 lines (33 loc) · 716 Bytes
/
11034.cpp
File metadata and controls
37 lines (33 loc) · 716 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <iostream>
#include <queue>
#include <string>
#define left 0
#define right 1
using namespace std;
int lens[100000];
int main() {
int tc; cin >> tc;
while (tc--) {
queue<int> cars[2];
int l, n;
cin >> l >> n;
l *= 100;
for (int i = 0; i < n; i++) {
string p;
cin >> lens[i] >> p;
cars[p == "right"].push(i);
}
int trips = 0, pos = left;
while (not cars[left].empty() or not cars[right].empty()) {
int len = l;
while (not cars[pos].empty() and len >= lens[cars[pos].front()]) {
len -=lens[cars[pos].front()];
cars[pos].pop();
}
pos = (pos+1)%2;
trips++;
}
cout << trips << endl;
}
return 0;
}