Cod sursa(job #2628195)
Utilizator | Data | 14 iunie 2020 20:59:12 | |
---|---|---|---|
Problema | Problema rucsacului | Scor | 35 |
Compilator | py | Status | done |
Runda | Arhiva educationala | Marime | 0.35 kb |
with open("rucsac.in", "r") as f, open("rucsac.out", "w") as g:
n, G = (int(i) for i in next(f).split())
a = [0] * (G + 1)
for i in range(n):
s = next(f).split()
w, p = int(s[0]), int(s[1])
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]))