Last active
May 11, 2022 23:56
-
-
Save sunho/68f65d160f4b98a2acaef494dafe0965 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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