Problem | Verdict | Lang | Time | Best | Rank | Submit Time |
---|---|---|---|---|---|---|
| discuss11034 - | Accepted | C++11 | 0.000 | 0.000 | 1133 | 12 mins ago |
#include <bits/stdc++.h>
#define int long long
using namespace std;
int t, n, L;
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> t;
while(t--){
cin >> L >> n; L*=100;
bool isLeft= true;
queue<int> left, right;
int x;
string y;
while(n--){
cin >> x >> y;
if (y=="left") left.push(x); else right.push(x);
}
int cnt= 0;
while(not left.empty() or not right.empty()){
cnt++;
if (isLeft){
isLeft= false;
int ferry= 0;
while (not left.empty() and ferry + left.front() <= L ){
ferry += left.front();
left.pop();
}
}
else{
isLeft= true;
int ferry= 0;
while (not right.empty() and ferry + right.front() <= L ){
ferry += right.front();
right.pop();
}
}
}
cout<<cnt<<"\n";
}
}
No comments:
Post a Comment