-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path210209.py
More file actions
72 lines (61 loc) · 1.4 KB
/
210209.py
File metadata and controls
72 lines (61 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
'''
https://www.acmicpc.net/problem/14501
퇴사 문제. 아래 주석 부분은 오답코드.
import numpy as np
from sys import stdin
timelist = []
worthlist = []
def main():
n = int(stdin.readline())
if not (n >=1) & (n <=15):
raise ValueError
for x in range(0,n):
line = stdin.readline()
t, w = line.split()
t = int(t)
w = int(w)
if not (t >=1) & (t <=5):
raise ValueError
if not (w >=1) & (w <=1000):
raise ValueError
timelist.append(t)
worthlist.append(w)
max_worth = 0
for x in range(0,n): # 0~14
profit = func(0,n,x)
try:
if profit > max_worth:
max_worth = profit
except:
print('day {} trial is failed!'.format(x+1))
print(max_worth)
def func(profit,max_date,cur_date):
#print('cur_date',cur_date)
#print('profit ',profit)
if max_date <= cur_date:
return profit
if max_date < (cur_date + timelist[cur_date]):
return profit
else:
profit += worthlist[cur_date]
cur_date += timelist[cur_date]
profit = func(profit, max_date, cur_date)
return profit
if __name__ == '__main__':
main()
'''
#정답코드
def main():
n = int(input())
timelist, worthlist = [0]*n, [0]*n
for i in range(n):
timelist[i], worthlist[i] = map(int, input().split())
dp = [0]*75
for i in range(n):
if dp[i] > dp[i+1]:
dp[i+1] = dp[i]
if dp[i+timelist[i]] < dp[i] + worthlist[i]:
dp[i+timelist[i]] = dp[i] + worthlist[i]
print(dp[n])
if __name__ == '__main__':
main()