Advertisement
Saleh127

UVA 11034 / Queue

Mar 26th, 2022
999
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.76 KB | None | 0 0
  1. /***
  2.  created: 2022-03-26-22.53.55
  3. ***/
  4.  
  5. #include <bits/stdc++.h>
  6. using namespace std;
  7. #define ll long long
  8. #define test int tt; cin>>tt; for(int cs=1;cs<=tt;cs++)
  9. #define get_lost_idiot return 0
  10. #define nl '\n'
  11.  
  12. int main()
  13. {
  14.     ios_base::sync_with_stdio(0);
  15.     cin.tie(0);
  16.     cout.tie(0);
  17.  
  18.  
  19.  
  20.     test
  21.     {
  22.         ll n,m,t,i,j,k,l;
  23.  
  24.         cin>>l>>m;
  25.  
  26.         queue<ll>x,y;
  27.  
  28.         l*=100;
  29.  
  30.         for(i=0;i<m;i++)
  31.         {
  32.             string a;
  33.  
  34.  
  35.             cin >>k >>a;
  36.  
  37.             if(a=="left") x.push(k);
  38.             else y.push(k);
  39.         }
  40.  
  41.         ll flag=0;
  42.  
  43.         n=0;
  44.  
  45.         while(!x.empty() || !y.empty())
  46.         {
  47.  
  48.             if(flag==0)
  49.             {
  50.                 if(x.empty())
  51.                 {
  52.                     //n++;
  53.                     flag^=1;
  54.                 }
  55.                 else
  56.                 {
  57.                     k=0;
  58.  
  59.                     while(!x.empty() &&  k+x.front()<=l)
  60.                     {
  61.                         k+=x.front();
  62.                         x.pop();
  63.                     }
  64.  
  65.                     //n++;
  66.                     flag^=1;
  67.                 }
  68.             }
  69.             else if(flag==1)
  70.             {
  71.                 if(y.empty())
  72.                 {
  73.                     //n++;
  74.                     flag^=1;
  75.                 }
  76.                 else
  77.                 {
  78.                     k=0;
  79.  
  80.                     while(!y.empty() &&  k+y.front()<=l)
  81.                     {
  82.                         k+=y.front();
  83.                         y.pop();
  84.                     }
  85.  
  86.                     //n++;
  87.                     flag^=1;
  88.                 }
  89.             }
  90.             n++;
  91.         }
  92.  
  93.         cout<<n<<nl;
  94.  
  95.     }
  96.  
  97.     get_lost_idiot;
  98. }
  99.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement