danielvitor23

D. Double Queue

Aug 2nd, 2023
1,202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.59 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.    
  3. using namespace std;
  4.    
  5. typedef long long int ll;
  6.    
  7. int main() {
  8.   ios::sync_with_stdio(false);
  9.   cin.tie(NULL);
  10.  
  11.   ll qa, qb, sa, sb, w, n, m;
  12.  
  13.   cin >> qa >> qb >> sa >> sb >> w >> n >> m;
  14.  
  15.   ll bob_time = qb * sb + sb + w;
  16.   ll alice_time = qa * sa + sa + w;
  17.  
  18.   vector<ll> aliceq(n), bobq(m);
  19.  
  20.   for (int i = 0; i < n; ++i) {
  21.     cin >> aliceq[i];
  22.   }
  23.  
  24.   for (int i = 0; i < m; ++i) {
  25.     cin >> bobq[i];
  26.   }
  27.  
  28.   ll ansBob = -1;
  29.   ll last = qb * sb;
  30.  
  31.   for (int i = 0; i < m; ++i) {
  32.     ll x = bobq[i];
  33.  
  34.     if (x > alice_time) {
  35.       if (alice_time < last) {
  36.         ansBob = last + sb;
  37.       } else {
  38.         ansBob = alice_time + sb;
  39.       }
  40.  
  41.       break;
  42.     }
  43.  
  44.     if (x < last) {
  45.       last += sb;
  46.     } else {
  47.       last = x + sb;
  48.     }
  49.   }
  50.  
  51.   if (ansBob == -1) {
  52.     if (alice_time < last) {
  53.       ansBob = last + sb;
  54.     } else {
  55.       ansBob = alice_time + sb;
  56.     }
  57.   }
  58.  
  59.   ll ansAlice = -1;
  60.   last = qa * sa;
  61.  
  62.   for (int i = 0; i < n; ++i) {
  63.     ll x = aliceq[i];
  64.  
  65.     if (x > bob_time) {
  66.       if (bob_time < last) {
  67.         ansAlice = last + sa;
  68.       } else {
  69.         ansAlice = bob_time + sa;
  70.       }
  71.  
  72.       break;
  73.     }
  74.  
  75.     if (x < last) {
  76.       last += sa;
  77.     } else {
  78.       last = x + sa;
  79.     }
  80.   }
  81.  
  82.   if (ansAlice == -1) {
  83.     if (bob_time < last) {
  84.       ansAlice = last + sa;
  85.     } else {
  86.       ansAlice = bob_time + sa;
  87.     }
  88.   }
  89.  
  90.   // cout << alice_time << ' ' << ansAlice << '\n';
  91.   // cout << bob_time << ' ' << ansBob << '\n';
  92.   cout << min(ansAlice, ansBob) << '\n';
  93. }
Advertisement
Add Comment
Please, Sign In to add comment