Ankit_132

E

Sep 9th, 2023
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1.  
  2. #include <bits/stdc++.h>
  3.  
  4. using namespace std;
  5. #define ll     long long
  6.  
  7. int main()
  8. {
  9.     ll int n, x, y;
  10.     cin>>n>>x>>y;
  11.  
  12.     vector<ll int> p(n-1), t(n-1);
  13.     for(int i=0; i<n-1; i++)
  14.         cin>>p[i]>>t[i];
  15.  
  16.     vector<ll int> ans(840);
  17.  
  18.     for(int i=0; i<840; i++)
  19.     {
  20.         ll int tot = i+x;
  21.  
  22.         for(int j=0; j<n-1; j++)
  23.             tot = ((tot + p[j] - 1) / p[j]) * p[j] + t[j];
  24.  
  25.         tot += y;
  26.  
  27.         ans[i] = tot;
  28.     }
  29.  
  30.     int q;
  31.     cin>>q;
  32.  
  33.     while(q--)
  34.     {
  35.         int tmp;
  36.         cin>>tmp;
  37.  
  38.         cout<<(tmp/840)*840 + ans[tmp%840]<<"\n";
  39.     }
  40. }
  41.  
Advertisement
Add Comment
Please, Sign In to add comment