Submission #2895413


Source Code Expand

from itertools import accumulate

N,W = map(int, input().split())
WV = []
for i in range(N):
    WV.append(list(map(int, input().split())))
    
    
w1 = WV[0][0]
w1p0 = [0]
w1p1 = [0]
w1p2 = [0]
w1p3 = [0]
for w, v in WV:
    if w == w1:
        w1p0.append(v)
    elif w == w1+1:
        w1p1.append(v)
    elif w == w1+2:
        w1p2.append(v)
    else:
        w1p3.append(v)
        
w1p0.sort()
w1p1.sort()
w1p2.sort()
w1p3.sort()

w1p0sum = list(accumulate(w1p0))
w1p1sum = list(accumulate(w1p1))
w1p2sum = list(accumulate(w1p2))
w1p3sum = list(accumulate(w1p3))

ans_cand = [0]
for p0 in range(len(w1p0sum)-1,-1,-1):
    if p0*w1 > W:
        continue
    
    for p1 in range(len(w1p1sum)-1,-1,-1):
        if p0*w1+p1+1*(w1+1) > W:
            continue
        
        for p2 in range(len(w1p2sum)-1,-1,-1):
            if p0*w1+p1*(w1+1)+p2*(w1+2) > W:
                continue
            
            for p3 in range(len(w1p3sum)-1,-1,-1):
                if p0*w1+p1*(w1+1)+p2*(w1+2)+p3*(w1+3) > W:
                    continue
                
                ans_cand.append(w1p0sum[p0]+w1p1sum[p1]\
                                +w1p2sum[p2]+w1p3sum[p3])
                
print(max(ans_cand))

Submission Info

Submission Time
Task D - Simple Knapsack
User polarbear08
Language Python (3.4.3)
Score 0
Code Size 1267 Byte
Status WA
Exec Time 223 ms
Memory 9888 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 400
Status
AC × 4
AC × 6
WA × 10
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 WA 18 ms 3188 KB
antigreedy1 WA 18 ms 3188 KB
antigreedy2 WA 19 ms 3188 KB
example0 AC 18 ms 3188 KB
example1 AC 18 ms 3064 KB
example2 AC 18 ms 3188 KB
example3 AC 18 ms 3188 KB
quarter0 WA 223 ms 9888 KB
quarter1 WA 149 ms 6836 KB
quarter2 WA 39 ms 3308 KB
rand0 AC 17 ms 3188 KB
rand1 AC 18 ms 3188 KB
rand2 WA 17 ms 3188 KB
smallw0 WA 18 ms 3064 KB
smallw1 WA 18 ms 3188 KB
smallw2 WA 22 ms 3188 KB