Skip to content

Instantly share code, notes, and snippets.

@sunho
Last active May 11, 2022 23:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sunho/68f65d160f4b98a2acaef494dafe0965 to your computer and use it in GitHub Desktop.
Save sunho/68f65d160f4b98a2acaef494dafe0965 to your computer and use it in GitHub Desktop.
# receive input
N, X = input().split()
N = int(N)
X = int(X)
A = []
B = []
for i in range(N):
a, b = input().split()
A.append(int(a))
B.append(int(b))
# solve
prev = [False] * (X+1)
prev[0] = True # Takahashi was initially at x = 0
for turn in range(N):
current = [False] * (X+1)
for x in range(X):
if prev[x]: # if it was able to reach x in the previous turn
if x + A[turn] <= X:
current[x+A[turn]] = True # mark x + A[turn] as possible
if x + B[turn] <= X:
current[x+B[turn]] = True # mark x + B[turn] as possible
prev = current
if prev[X]:
print("Yes")
else:
print("No")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment