Skip to content

Instantly share code, notes, and snippets.

@keddad
Created July 26, 2019 13:19
Show Gist options
  • Save keddad/0474cd2061e8b15382b3f7f3735e3a71 to your computer and use it in GitHub Desktop.
Save keddad/0474cd2061e8b15382b3f7f3735e3a71 to your computer and use it in GitHub Desktop.
def main():
with open("input.txt", "r") as inp:
with open("output.txt", "w") as out:
n, m = map(int, inp.__next__().split())
w = [int(x) for x in inp.__next__().split()]
dp = [[0 for _ in range(m + 1)] for _ in range(n + 1)]
for i in range(1, n + 1):
for j in range(1, m + 1):
if j >= w[i - 1]:
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i - 1]] + w[i - 1])
else:
dp[i][j] = dp[i - 1][j]
if dp[i][j] == m:
out.write("YES")
return
out.write("NO")
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment