Advertisement
7oSkaaa

Steps

Aug 10th, 2021
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.72 KB | None | 0 0
  1.   #include <bits/stdc++.h>
  2.   using namespace std;
  3.  
  4.   #define cin(vec) for(auto& i : vec) cin >> i
  5.   #define cin_2d(vec, n, m) for(int i = 0; i < n; i++) for(int j = 0; j < m && cin >> vec[i][j]; j++);
  6.   #define cout(vec) for(auto& i : vec) cout << i << " "; cout << "\n";
  7.   #define cout_map(mp) for(auto& [f, s] : mp) cout << f << "  " << s << "\n";
  8.   #define loop(a, b, c) for(int i = a ; i < (b); i += c)
  9.   #define fixed(n) cout << fixed << setprecision(n);
  10.   #define ceil(n, m) (((n) / (m)) + (n % m ? 1 : 0))
  11.   #define all(vec) vec.begin(),vec.end()
  12.   #define rall(vec) vec.rbegin(),vec.rend()
  13.   #define sz size()
  14.   #define fi first
  15.   #define se second
  16.   #define Pair pair <int,int>
  17.   #define ll long long
  18.   #define ull unsigned long long
  19.   #define Mod  1000'000'007
  20.   #define INF 2000'000'000
  21.   #define PI 3.14159265359
  22.  
  23.   void Code_Crush(){
  24.     ios_base::sync_with_stdio(false);   cin.tie(nullptr);   cout.tie(nullptr);
  25.     #ifndef ONLINE_JUDGE
  26.       freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  27.     #endif
  28.   }
  29.   ll n, m, x, y;
  30.   bool valid(ll mid, ll x1, ll y1){
  31.     return ((x + (mid * x1)) <= n && x + (mid * x1) > 0 && (y + (mid * y1)) <= m && (y + (mid * y1)) > 0);
  32.   }
  33.   ll Binary_Search(ll x1, ll y1){
  34.     ll l = 1, r = 1e9, best = 0;
  35.     while(l <= r){
  36.       ll mid = l + (r - l) / 2;
  37.       if(valid(mid, x1, y1)) l = mid + 1, best = mid;
  38.       else r = mid - 1;
  39.     }
  40.     x += best * x1, y += best * y1;
  41.     return best;
  42.   }
  43.   int main(){
  44.     Code_Crush();
  45.     ll k, res = 0;
  46.     cin >> n >> m >> x >> y >> k;
  47.     while(k--){
  48.       ll x1, y1;                  cin >> x1 >> y1;
  49.       res += Binary_Search(x1, y1);
  50.     }
  51.     cout << res << "\n";
  52.     return 0;
  53.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement