forked from ndb796/python-for-coding-test
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path3.py
More file actions
24 lines (21 loc) Β· 762 Bytes
/
3.py
File metadata and controls
24 lines (21 loc) Β· 762 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
n = int(input()) # μ 체 μλ΄ κ°μ
t = [] # κ° μλ΄μ μλ£νλλ° κ±Έλ¦¬λ κΈ°κ°
p = [] # κ° μλ΄μ μλ£νμ λ λ°μ μ μλ κΈμ‘
dp = [0] * (n + 1) # λ€μ΄λλ―Ή νλ‘κ·Έλλ°μ μν 1μ°¨μ DP ν
μ΄λΈ μ΄κΈ°ν
max_value = 0
for _ in range(n):
x, y = map(int, input().split())
t.append(x)
p.append(y)
# 리μ€νΈλ₯Ό λ€μμλΆν° κ±°κΎΈλ‘ νμΈ
for i in range(n - 1, -1, -1):
time = t[i] + i
# μλ΄μ΄ κΈ°κ° μμ λλλ κ²½μ°
if time <= n:
# μ νμμ λ§κ², νμ¬κΉμ§μ μ΅κ³ μ΄μ΅ κ³μ°
dp[i] = max(p[i] + dp[time], max_value)
max_value = dp[i]
# μλ΄μ΄ κΈ°κ°μ λ²μ΄λλ κ²½μ°
else:
dp[i] = max_value
print(max_value)