| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1355050 | li1005345206 | Knapsack (NOI18_knapsack) | Pypy 3 | 313 ms | 327680 KiB |
import os
import sys
from collections import deque
input=lambda:sys.stdin.readline().strip()
minput=lambda:map(int,input().split())
S,N=minput()
kvw=[minput() for i in range(N)]
kvw=deque(kvw)
for i in range(N):
V,W,K=kvw.popleft()
base = 1
while K >= base:
K -= base
kvw.append((V * base, W * base, 1))
base <<= 1
if K > 0:
kvw.append((V * K, W * K, 1))
n = len(kvw)
dp = [[0] * (S + 1) for _ in range(2)]
for i in range(n):
V,W,K = kvw[i]
ind = (i + 1) & 1
prev = i & 1
for j in range(S + 1):
## print(j)
dp[ind][j] = dp[prev][j]
if j >= W:
dp[ind][j] = max(dp[ind][j], dp[prev][j - W] + V)
##print(kvw, dp)
print(max(map(max, dp)))
Compilation message (stdout)
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
