Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define ll long long int
- #ifdef ERFANUL007
- #define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
- template < typename Arg1 >
- void __f(const char* name, Arg1&& arg1){
- cout << name << " = " << arg1 << std::endl;
- }
- template < typename Arg1, typename... Args>
- void __f(const char* names, Arg1&& arg1, Args&&... args){
- const char* comma = strchr(names, ',');
- cout.write(names, comma - names) << " = " << arg1 <<" | ";
- __f(comma+1, args...);
- }
- #else
- #define debug(...)
- #endif
- int main(){
- #ifdef ERFANUL007
- clock_t tStart = clock();
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- int t;
- cin >> t;
- //debug(t);
- while(t--){
- ll l;
- int m;
- cin >> l >> m;
- //debug(l, m);
- l *= 100;
- vector< int > left, right;
- for(int i=0; i < m; i++){
- ll x;
- string s;
- cin >> x >> s;
- //debug(x, s);
- if(s == "left") left.push_back(x);
- else right.push_back(x);
- }
- int cnt = 0, i=0, j=0;
- while(i < left.size() || j<right.size()){
- if(cnt % 2 == 0){
- ll sum = 0;
- while(i < left.size()){
- if(sum + left[i] > l) break;
- sum += left[i++];
- }
- }
- else{
- ll sum = 0;
- while(j < right.size()){
- if(sum + right[j] > l) break;
- sum += right[j++];
- }
- }
- cnt++;
- //debug(cnt);
- }
- cout << cnt << '\n';
- }
- #ifdef ERFANUL007
- fprintf(stderr, ">>> Runtime : %.9f\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
- #endif
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement