Skip to content

Commit 1190994

Browse files
committed
[BOJ] #1495.기타리스트 / 실버1 / 60(X)
1 parent 2b83eb2 commit 1190994

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import sys
2+
input = sys.stdin.readline
3+
4+
N,S,M = map(int,input().split())
5+
V = list(map(int,input().split()))
6+
7+
dp = [[0]*(M+1) for _ in range(N+1)]
8+
dp[0][S] = 1 # 시작 볼륨을 설정
9+
10+
for i in range(1, N+1): # 각 곡에 대해
11+
for j in range(M+1): # 가능한 볼륨에 대해
12+
if dp[i-1][j] != 0: # 이전 곡에서 해당 볼륨이 가능하다면
13+
if 0 <= j + V[i-1] <= M: # 볼륨을 올릴 수 있다면
14+
dp[i][j + V[i-1]] = 1
15+
if 0 <= j - V[i-1] <= M: # 볼륨을 낮출 수 있다면
16+
dp[i][j-V[i-1]] = 1
17+
volume = -1
18+
for i in range(M, -1, -1): # 최대 볼륨부터 탐색
19+
if dp[N][i] == 1: # 가능한 볼륨을 찾으면
20+
volume = i
21+
break
22+
23+
print(volume)

0 commit comments

Comments
 (0)