Advertisement
Saleh127

UVA 10901 / Queue

Mar 24th, 2022
790
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.39 KB | None | 0 0
  1. /***
  2.  created: 2022-03-24-20.10.01
  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>>n>>t>>m;
  25.  
  26.         queue<pair<ll,ll>>q[5];
  27.  
  28.  
  29.         for(i=0;i<m;i++)
  30.         {
  31.             string a;
  32.  
  33.  
  34.             cin >>k >>a;
  35.  
  36.             if(a=="left") q[0].push({k,i});
  37.             else q[1].push({k,i});
  38.         }
  39.  
  40.         vector<ll>ans(m);
  41.  
  42.         ll flag=0;
  43.  
  44.         l=0;
  45.  
  46.         while(!q[0].empty() || !q[1].empty())
  47.         {
  48.             j=0;
  49.  
  50.             if(q[0].empty()) k=q[1].front().first;
  51.  
  52.             else if(q[1].empty()) k=q[0].front().first;
  53.  
  54.             else
  55.             {
  56.                 k=min(q[0].front().first,q[1].front().first);
  57.             }
  58.  
  59.             l=max(l,k);
  60.  
  61.  
  62.             while(q[flag].empty()==false && j<n && q[flag].front().first<=l)
  63.             {
  64.                 ans[q[flag].front().second]=l+t;
  65.                 q[flag].pop();
  66.                 j++;
  67.             }
  68.  
  69.             l+=t;
  70.  
  71.             flag^=1;
  72.  
  73.         }
  74.  
  75.         if(cs>1) cout<<nl;
  76.  
  77.         for(auto d:ans)
  78.         {
  79.             cout<<d<<nl;
  80.         }
  81.  
  82.     }
  83.  
  84.     get_lost_idiot;
  85. }
  86.  
  87.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement