Submission #4414027


Source Code Expand

Copy
N,W = map(int,input().split())
L = []
for i in range(N):
  L.append(list(map(int,input().split())))
Vmax = 0
w_1 = []
w_2 = []
w_3 = []
w_4 = []
for i in range(N):
  if L[i][0] == L[0][0]:
    w_1.append(L[i][1])
  elif L[i][0] == L[0][0]+1:
    w_2.append(L[i][1])
  elif L[i][0] == L[0][0]+2:
    w_3.append(L[i][1])
  else:
    w_4.append(L[i][1])
w_1.sort()
w_2.sort()
w_3.sort()
w_4.sort()
w_1.reverse()
w_2.reverse()
w_3.reverse()
w_4.reverse()
for i in range(1,len(w_1)):
  w_1[i] = w_1[i-1]+w_1[i]
for i in range(1,len(w_2)):
  w_2[i] = w_2[i-1]+w_2[i]
for i in range(1,len(w_3)):
  w_3[i] = w_3[i-1]+w_3[i]
for i in range(1,len(w_4)):
  w_4[i] = w_4[i-1]+w_4[i]
w_1.append(0)
w_2.append(0)
w_3.append(0)
w_4.append(0)
for j in range(len(w_1)):
  for k in range(len(w_2)):
    for l in range(len(w_3)):
      for m in range(len(w_4)):
        if j*L[0][0]+k*(L[0][0]+1)+l*(L[0][0]+2)+m*(L[0][0]+3) > W:
          continue
        else:
          if w_1[j-1]+w_2[k-1]+w_3[l-1]+w_4[m-1] >= Vmax:
            Vmax = w_1[j-1]+w_2[k-1]+w_3[l-1]+w_4[m-1]
print(Vmax)

Submission Info

Submission Time
Task D - Simple Knapsack
User Syuko4omi
Language Python (3.4.3)
Score 400
Code Size 1115 Byte
Status
Exec Time 335 ms
Memory 3192 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
× 4
× 16
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 18 ms 3192 KB
antigreedy1 18 ms 3192 KB
antigreedy2 18 ms 3192 KB
example0 17 ms 3192 KB
example1 17 ms 3192 KB
example2 17 ms 3192 KB
example3 17 ms 3192 KB
quarter0 335 ms 3192 KB
quarter1 315 ms 3192 KB
quarter2 284 ms 3192 KB
rand0 17 ms 3192 KB
rand1 38 ms 3192 KB
rand2 18 ms 3192 KB
smallw0 281 ms 3192 KB
smallw1 287 ms 3192 KB
smallw2 250 ms 3192 KB