-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuva11034.cpp
More file actions
70 lines (63 loc) · 1.74 KB
/
uva11034.cpp
File metadata and controls
70 lines (63 loc) · 1.74 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include<iostream>
#include<queue>
#include<string>
using namespace std;
enum class FS {
left,
right,
};
int main() {
int ncases;
cin >> ncases;
while(ncases--) {
int l,m;
cin >> l >> m;
l *= 100;
queue<int> lcars, rcars;
for (int i = 0; i < m; i++) {
int t; string s;
cin >> t >> s;
if (s == "left") {
lcars.push(t);
} else {
rcars.push(t);
}
}
int ntrips = 0;
FS fs = FS::left;
while(lcars.size() or rcars.size()) {
if (fs == FS::left and lcars.size()) {
int currlength = 0;
while(not lcars.empty() and currlength < l) {
if (currlength + lcars.front() <= l) {
currlength += lcars.front();
lcars.pop();
} else {
break;
}
}
ntrips++;
fs = FS::right;
} else if (fs == FS::right and not rcars.empty()) {
int currlength = 0;
while(not rcars.empty() and currlength < l) {
if (currlength + rcars.front() <= l) {
currlength += rcars.front();
rcars.pop();
} else {
break;
}
}
ntrips++;
fs = FS::left;
} else {
if (fs == FS::left)
fs = FS::right;
else
fs = FS::left;
ntrips++;
}
}
cout << ntrips << endl;
}
}