Submission #8522301


Source Code Expand

import bisect
N,W=map(int,input().split())
wv=[list(map(int,input().split())) for _ in range(N)]
w1=wv[0][0]

Wlist=[0]+[j*(w1+i) for j in range(1,N+1) for i in range(4)]
Wlist=sorted(set(Wlist))
LW=len(Wlist)
dp=[[0]*LW for _ in range(N+1)]
#dp[i][j]:N個の物に対して強度(Wlist[j])のバッグ


for i in range(1,N+1):
  w,v=wv[i-1]
  for j in range(LW):
    if w<=Wlist[j]:      
      ind=bisect.bisect_right(Wlist,Wlist[j]-w)-1
      
      dp[i][j]=max(dp[i-1][j],dp[i-1][ind]+v)
    else:
      dp[i][j]=dp[i-1][j]

ind=bisect.bisect_right(Wlist,W)-1
print(dp[N][ind])

Submission Info

Submission Time
Task D - Simple Knapsack
User Wattawa
Language Python (3.4.3)
Score 0
Code Size 605 Byte
Status WA
Exec Time 63 ms
Memory 4328 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 400
Status
AC × 4
AC × 12
WA × 4
Set Name Test Cases
Sample example0, example1, example2, example3
All antigreedy0, antigreedy1, antigreedy2, example0, example1, example2, example3, quarter0, quarter1, quarter2, rand0, rand1, rand2, smallw0, smallw1, smallw2
Case Name Status Exec Time Memory
antigreedy0 AC 62 ms 4328 KB
antigreedy1 AC 61 ms 4328 KB
antigreedy2 AC 62 ms 4328 KB
example0 AC 17 ms 3064 KB
example1 AC 17 ms 3064 KB
example2 AC 17 ms 3064 KB
example3 AC 17 ms 3064 KB
quarter0 WA 60 ms 4200 KB
quarter1 WA 61 ms 4200 KB
quarter2 WA 61 ms 4200 KB
rand0 AC 18 ms 3064 KB
rand1 AC 28 ms 3312 KB
rand2 AC 20 ms 3064 KB
smallw0 AC 62 ms 4324 KB
smallw1 AC 63 ms 4324 KB
smallw2 WA 59 ms 4184 KB