Skip to content

Instantly share code, notes, and snippets.

@inspirit941
Created December 18, 2019 15:51
Show Gist options
  • Save inspirit941/8368011f79c022735110178140c5493c to your computer and use it in GitHub Desktop.
Save inspirit941/8368011f79c022735110178140c5493c to your computer and use it in GitHub Desktop.
import sys
N, S, M = map(int, sys.stdin.readline().split())
V = list(map(int, sys.stdin.readline().split()))
# 모든 볼륨에 관해 연주 가능 여부를 계산하기.
result = [[0 for _ in range(M+1)] for _ in range(N+1)]
result[0][S] = 1
# 정확히 이렇게 풀어아먄 메모리 초과도, 시간 초과도 안 난다.
for i in range(1, N+1):
for j in range(M+1):
if result[i-1][j] == 0:
continue
if j + V[i-1] <= M:
result[i][j+V[i-1]] = 1
if j - V[i-1] >= 0:
result[i][j-V[i-1]] = 1
idx = -1
for i in range(M, -1 , -1):
if result[-1][i] == 1:
idx = i
break
print(idx)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment