Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define cin(vec) for(auto& i : vec) cin >> i
- #define cin_2d(vec, n, m) for(int i = 0; i < n; i++) for(int j = 0; j < m && cin >> vec[i][j]; j++);
- #define cout(vec) for(auto& i : vec) cout << i << " "; cout << "\n";
- #define cout_map(mp) for(auto& [f, s] : mp) cout << f << " " << s << "\n";
- #define loop(a, b, c) for(int i = a ; i < (b); i += c)
- #define fixed(n) cout << fixed << setprecision(n);
- #define ceil(n, m) (((n) / (m)) + (n % m ? 1 : 0))
- #define all(vec) vec.begin(),vec.end()
- #define rall(vec) vec.rbegin(),vec.rend()
- #define sz size()
- #define fi first
- #define se second
- #define Pair pair <int,int>
- #define ll long long
- #define ull unsigned long long
- #define Mod 1000'000'007
- #define INF 2000'000'000
- #define PI 3.14159265359
- void Code_Crush(){
- ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
- #ifndef ONLINE_JUDGE
- freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
- #endif
- }
- ll n, m, x, y;
- bool valid(ll mid, ll x1, ll y1){
- return ((x + (mid * x1)) <= n && x + (mid * x1) > 0 && (y + (mid * y1)) <= m && (y + (mid * y1)) > 0);
- }
- ll Binary_Search(ll x1, ll y1){
- ll l = 1, r = 1e9, best = 0;
- while(l <= r){
- ll mid = l + (r - l) / 2;
- if(valid(mid, x1, y1)) l = mid + 1, best = mid;
- else r = mid - 1;
- }
- x += best * x1, y += best * y1;
- return best;
- }
- int main(){
- Code_Crush();
- ll k, res = 0;
- cin >> n >> m >> x >> y >> k;
- while(k--){
- ll x1, y1; cin >> x1 >> y1;
- res += Binary_Search(x1, y1);
- }
- cout << res << "\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement