Pagini recente » Cod sursa (job #1769533) | Cod sursa (job #2600580) | Cod sursa (job #291836) | Cod sursa (job #1266168) | Cod sursa (job #2628196)
with open("rucsac.in", "r") as f, open("rucsac.out", "w") as g:
n, G = (int(i) for i in next(f).split())
a, W, P = [0] * (G + 1), [0] * (G + 1), [0] * (n + 1)
for i in range(1, n + 1):
W[i], P[i] = (int(j) for j in next(f).split())
for i in range(1, n + 1):
w, p = W[i], P[i]
for j in range(G, w - 1, -1):
if a[j - w] + p > a[j]:
a[j] = a[j - w] + p
g.write(str(a[G]))