Submission #3441815
Source Code Expand
N, W = map(int, input().split()) app = [list(map(int, input().split())) for i in range(N)] data = [[] for i in range(4)] for w, v in app: if w == app[0][0]: data[0].append(v) elif w == app[0][0] + 1: data[1].append(v) elif w == app[0][0] + 2: data[2].append(v) elif w == app[0][0] + 3: data[3].append(v) for i in range(4): data[i].sort(reverse=True) for i in range(4): for j in range(len(data[i])-1): data[i][j+1] += data[i][j] for i in range(4): data[i].append(0) data[i].sort() ans = 0 for a in range(len(data[0])): for b in range(len(data[1])): for c in range(len(data[2])): for d in range(len(data[3])): if a * app[0][0] + b * (app[0][0]+1) + c * (app[0][0]+2) + d * (app[0][0]+3) <= W: ans = max(ans, data[0][a] + data[1][b] + data[2][c] + data[3][d]) print(ans)
Submission Info
Submission Time | |
---|---|
Task | D - Simple Knapsack |
User | mizukurage |
Language | Python (3.4.3) |
Score | 400 |
Code Size | 940 Byte |
Status | AC |
Exec Time | 396 ms |
Memory | 3064 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 400 / 400 | ||||
Status |
|
|
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 | 17 ms | 3064 KB |
antigreedy1 | AC | 17 ms | 3064 KB |
antigreedy2 | AC | 17 ms | 3064 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 | AC | 396 ms | 3064 KB |
quarter1 | AC | 344 ms | 3064 KB |
quarter2 | AC | 282 ms | 3064 KB |
rand0 | AC | 17 ms | 3064 KB |
rand1 | AC | 38 ms | 3064 KB |
rand2 | AC | 18 ms | 3064 KB |
smallw0 | AC | 282 ms | 3064 KB |
smallw1 | AC | 301 ms | 3064 KB |
smallw2 | AC | 249 ms | 3064 KB |