-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUVA-11034.cpp
More file actions
41 lines (37 loc) · 1015 Bytes
/
UVA-11034.cpp
File metadata and controls
41 lines (37 loc) · 1015 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
38
39
40
41
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int main() {
int c, l, m, side, viagens, soma;
queue<int> left, right;
scanf("%d", &c);
while(c--) {
scanf("%d %d", &l, &m);
l = l*100;
int temp;
char s[50];
while(m--) {
scanf("%d %s", &temp, s);
if(s[0] == 'l')
left.push(temp);
else
right.push(temp);
}
side = 0, viagens = 0;
while(!left.empty() || !right.empty()) {
viagens++;
soma = 0;
if(side == 1) {
while(!right.empty() && soma + right.front() <= l)
soma += right.front(), right.pop();
} else {
while(!left.empty() && soma + left.front() <= l)
soma += left.front(), left.pop();
}
side = !side;
}
printf("%d\n", viagens);
}
return 0;
}