Submission #67004306
Source Code Expand
import heapq
T=int(input())
ans_f=[]
for _ in range(T):
N,W=map(int, input().split())
digit = 60
xs = [[] for _ in range(digit)]
for _ in range(N):
x,y = map(int, input().split())
xs[x].append(y)
for i in range(digit):
xs[i].sort(reverse=True)
box=[]
ans=0
for i in range(digit):
for x in xs[i]:
heapq.heappush(box, -x)
if (1<<i)&W and len(box) > 0:
p = heapq.heappop(box)
ans-=p
box_d = []
while len(box) > 0:
if len(box) >= 2:
p1 = heapq.heappop(box)
p2 = heapq.heappop(box)
heapq.heappush(box_d, p1 + p2)
else:
p1 = heapq.heappop(box)
heapq.heappush(box_d, p1)
box = box_d
ans_f.append(ans)
for ans in ans_f:
print(ans)
Submission Info
| Submission Time | |
|---|---|
| Task | B - Binary Knapsack |
| User | nikoro256 |
| Language | Python (PyPy 3.10-v7.3.12) |
| Score | 500 |
| Code Size | 932 Byte |
| Status | AC |
| Exec Time | 423 ms |
| Memory | 102412 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 500 / 500 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | sample-01.txt |
| All | 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 02-01.txt, 02-02.txt, 02-03.txt, 02-04.txt, 02-05.txt, 02-06.txt, 02-07.txt, 02-08.txt, 02-09.txt, 02-10.txt, 03-01.txt, 03-02.txt, 03-03.txt, 03-04.txt, 03-05.txt, 03-06.txt, 03-07.txt, hand-01.txt, sample-01.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 01-01.txt | AC | 423 ms | 92184 KiB |
| 01-02.txt | AC | 255 ms | 85208 KiB |
| 01-03.txt | AC | 282 ms | 86504 KiB |
| 01-04.txt | AC | 257 ms | 86040 KiB |
| 01-05.txt | AC | 289 ms | 88344 KiB |
| 01-06.txt | AC | 273 ms | 91076 KiB |
| 01-07.txt | AC | 278 ms | 91688 KiB |
| 01-08.txt | AC | 339 ms | 87620 KiB |
| 01-09.txt | AC | 295 ms | 87936 KiB |
| 01-10.txt | AC | 291 ms | 86260 KiB |
| 01-11.txt | AC | 293 ms | 87528 KiB |
| 01-12.txt | AC | 273 ms | 91668 KiB |
| 01-13.txt | AC | 287 ms | 91856 KiB |
| 01-14.txt | AC | 305 ms | 88140 KiB |
| 01-15.txt | AC | 292 ms | 91300 KiB |
| 01-16.txt | AC | 290 ms | 91084 KiB |
| 02-01.txt | AC | 295 ms | 86844 KiB |
| 02-02.txt | AC | 289 ms | 88244 KiB |
| 02-03.txt | AC | 294 ms | 92812 KiB |
| 02-04.txt | AC | 269 ms | 94032 KiB |
| 02-05.txt | AC | 275 ms | 87392 KiB |
| 02-06.txt | AC | 241 ms | 92724 KiB |
| 02-07.txt | AC | 217 ms | 91868 KiB |
| 02-08.txt | AC | 296 ms | 87988 KiB |
| 02-09.txt | AC | 302 ms | 93432 KiB |
| 02-10.txt | AC | 249 ms | 93252 KiB |
| 03-01.txt | AC | 165 ms | 102412 KiB |
| 03-02.txt | AC | 185 ms | 102324 KiB |
| 03-03.txt | AC | 194 ms | 102296 KiB |
| 03-04.txt | AC | 237 ms | 90392 KiB |
| 03-05.txt | AC | 273 ms | 91192 KiB |
| 03-06.txt | AC | 223 ms | 92156 KiB |
| 03-07.txt | AC | 284 ms | 92536 KiB |
| hand-01.txt | AC | 59 ms | 76424 KiB |
| sample-01.txt | AC | 59 ms | 76424 KiB |