Pagini recente » Cod sursa (job #3227256) | Cod sursa (job #2320253) | Cod sursa (job #3291820) | Cod sursa (job #2200583) | Cod sursa (job #2533186)
file = open("rucsac.in", "r")
N, G = map(int, file.readline().split())
v = []
for _ in range(N):
c, p = map(int, file.readline().split())
v.append([c, p])
pd = [(0 for _ in range(G+1)) for __ in range(N+1)]
for n in range(N):
for g in range(1, G+1):
pd[n][g] = -1
if n > 0:
pd[n][g] = pd[n-1][g]
if g >= v[n][0]:
pd[n][g] = max(pd[n][g], v[n][1]+pd[n-1][g-v[n][1]])
print(pd[N-1][G])