Skip to content

Instantly share code, notes, and snippets.

@maehrm
Created February 11, 2026 02:24
Show Gist options
  • Select an option

  • Save maehrm/ba963bd81e52cef0a1404df164e9e1c1 to your computer and use it in GitHub Desktop.

Select an option

Save maehrm/ba963bd81e52cef0a1404df164e9e1c1 to your computer and use it in GitHub Desktop.
from itertools import permutations
def need_w(s, h):
return (s + h - 1) // h
def need_h(s, w):
return (s + w - 1) // w
def check():
for a, b, c in permutations([A, B, C]):
# 横に3つ
if need_w(a, Y) + need_w(b, Y) + need_w(c, Y) <= X:
return True
# 縦に3つ
if need_h(a, X) + need_h(b, X) + need_h(c, X) <= Y:
return True
# 上1個、下に横2個
hA = need_h(a, X)
if hA < Y:
rest = Y - hA
# 残りの部分に2つ横に並べられるか?
if need_w(b, rest) + need_w(c, rest) <= X:
return True
# 左1個、右に縦2個
wA = need_w(a, Y)
if wA < X:
rest = X - wA
if need_h(b, rest) + need_h(c, rest) <= Y:
return True
return False
X, Y, A, B, C = map(int, input().split())
print("Yes" if check() else "No")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment