Submission #1222335

#TimeUsernameProblemLanguageResultExecution timeMemory
1222335marcusufabcKnapsack (NOI18_knapsack)Pypy 3
37 / 100
1094 ms51112 KiB
max_weight, num_items = map(int, input().split())

weights = []
values = []
available_quantity = []

for _ in range(num_items):
    value, weight, qnt = map(int, input().split())
    weights.append(weight)
    values.append(value)
    available_quantity.append(qnt)

# d[i] is the maximum value we can achieve with a basket of weight i
dp = [0] * (max_weight + 1)

# iterate through items
for i in range(num_items):
    weight = weights[i]
    value = values[i]
    quantity = available_quantity[i]

    # process each item for each available unit of it
    for q in range(1, quantity + 1):
        for w in range(max_weight, weight - 1, -1):
            dp[w] = max(dp[w], dp[w - weight] + value)

print(dp[max_weight])

Compilation message (stdout)

Compiling 'knapsack.py'...

=======
  adding: __main__.pyc (deflated 28%)

=======
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...