-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path11034.cpp
56 lines (53 loc) · 946 Bytes
/
11034.cpp
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
#include <iostream>
#include <queue>
#define foi( i , n , k ) for(int i = n ; i < k ; ++i )
using namespace std;
int main()
{
int c;
scanf("%d",&c);
while(c--)
{
int l,m,lon;
string dir;
scanf("%d%d",&l,&m);
l*=100;
queue<int> left,right;
foi( i , 0 , m )
{
scanf("%d",&lon);
cin>>dir;
if(dir=="left")
left.push(lon);
else
right.push(lon);
}
bool pos=true;
int tot=0;
while( !left.empty() || !right.empty() )
{
int lm=0;
if( pos )
{
while( !left.empty() && lm+left.front() <= l )
{
lm+=left.front();
left.pop();
}
pos=!pos;
}
else
{
while( !right.empty() && lm+right.front() <= l )
{
lm+=right.front();
right.pop();
}
pos=!pos;
}
tot++;
}
printf("%d\n",tot);
}
return 0;
}