Advertisement
Josif_tepe

Untitled

Mar 9th, 2025
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.58 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <cmath>
  4. using namespace std;
  5. typedef long long ll;
  6.  
  7. ll distance(ll x, ll y, ll x2, ll y2) {
  8.     return llabs(x - x2) + llabs(y - y2);
  9. }
  10. int main() {
  11.     ll w, h, c, r;
  12.    
  13.     cin >> w >> h >> c >> r;
  14.    
  15.     ll a = h / r;
  16.     ll b = w / c;
  17.     ll res = 1e18;
  18.     for(ll i = a - 1; i <= a + 1; i++) {
  19.         res = min(res, distance(w, h, i * c, i * r));
  20.     }
  21.     for(ll i = b - 1; i <= b + 1; i++) {
  22.         res = min(res, distance(w, h, i * c, i * r));
  23.     }
  24.     cout << res << endl;
  25.    
  26.    
  27.     return 0;
  28. }
  29.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement