Advertisement
serega1112

Mars

Dec 6th, 2020
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.39 KB | None | 0 0
  1. n, a, b, w, h = map(int, input().split())
  2.  
  3. def check(d):
  4.     hor = w // (a + 2 * d)
  5.     ver = h // (b + 2 * d)
  6.     total = hor * ver
  7.     hor = h // (a + 2 * d)
  8.     ver = w // (b + 2 * d)
  9.     total = max(total, hor * ver)
  10.     return total >= n
  11.  
  12. l = 0
  13. r = max(w, h) // 2 + 2
  14.  
  15. while r - l > 1:
  16.     d = l + (r - l) // 2
  17.     if check(d):
  18.         l = d
  19.     else:
  20.         r = d
  21.  
  22. print(l)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement