Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <cmath>
- using namespace std;
- typedef long long ll;
- ll distance(ll x, ll y, ll x2, ll y2) {
- return llabs(x - x2) + llabs(y - y2);
- }
- int main() {
- ll w, h, c, r;
- cin >> w >> h >> c >> r;
- ll a = h / r;
- ll b = w / c;
- ll res = 1e18;
- for(ll i = a - 1; i <= a + 1; i++) {
- res = min(res, distance(w, h, i * c, i * r));
- }
- for(ll i = b - 1; i <= b + 1; i++) {
- res = min(res, distance(w, h, i * c, i * r));
- }
- cout << res << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement