Submission #67003678
Source Code Expand
Copy
T=int(input())for _ in range(T):N,W=map(int, input().split())bit=[[] for _ in range(60)]for i in range(N):x,y=map(int, input().split())bit[x].append(y)px=[]sz=[]for i in range(60):a=sorted(bit[i],reverse=True)ps=[0]for v in a:ps.append(ps[-1]+v)px.append(ps)sz.append(len(a))
T=int(input())
for _ in range(T):
N,W=map(int, input().split())
bit=[[] for _ in range(60)]
for i in range(N):
x,y=map(int, input().split())
bit[x].append(y)
px=[]
sz=[]
for i in range(60):
a=sorted(bit[i],reverse=True)
ps=[0]
for v in a:
ps.append(ps[-1]+v)
px.append(ps)
sz.append(len(a))
dp={0:0}
for i in range(59,-1,-1):
msk=(W>>i)&1
sb=sz[i]
ps=px[i]
ndp={}
for c,val in dp.items():
u=c+msk
mx=min(u,sb)
for k in range(mx+1):
nv=val+ps[k]
nc=(u-k)*2
if nc not in ndp or ndp[nc]<nv:
ndp[nc]=nv
dp=ndp
print((max(dp.values())))
Submission Info
| Submission Time | |
|---|---|
| Task | B - Binary Knapsack |
| User | kotafuku |
| Language | Python (PyPy 3.10-v7.3.12) |
| Score | 0 |
| Code Size | 842 Byte |
| Status | TLE |
| Exec Time | 2257 ms |
| Memory | 994176 KiB |
Judge Result
| Set Name | Sample | All | ||||||
|---|---|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 0 / 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 | 1058 ms | 86232 KiB |
| 01-02.txt | TLE | 2229 ms | 441352 KiB |
| 01-03.txt | TLE | 2255 ms | 940764 KiB |
| 01-04.txt | TLE | 2227 ms | 483600 KiB |
| 01-05.txt | TLE | 2217 ms | 209952 KiB |
| 01-06.txt | TLE | 2212 ms | 103204 KiB |
| 01-07.txt | TLE | 2212 ms | 102932 KiB |
| 01-08.txt | AC | 1584 ms | 90052 KiB |
| 01-09.txt | TLE | 2248 ms | 809620 KiB |
| 01-10.txt | TLE | 2248 ms | 766060 KiB |
| 01-11.txt | TLE | 2214 ms | 156632 KiB |
| 01-12.txt | TLE | 2212 ms | 110028 KiB |
| 01-13.txt | TLE | 2212 ms | 106608 KiB |
| 01-14.txt | TLE | 2216 ms | 185536 KiB |
| 01-15.txt | TLE | 2211 ms | 100060 KiB |
| 01-16.txt | TLE | 2212 ms | 103680 KiB |
| 02-01.txt | TLE | 2233 ms | 539868 KiB |
| 02-02.txt | TLE | 2218 ms | 255684 KiB |
| 02-03.txt | TLE | 2213 ms | 128552 KiB |
| 02-04.txt | TLE | 2212 ms | 104092 KiB |
| 02-05.txt | TLE | 2220 ms | 273480 KiB |
| 02-06.txt | TLE | 2212 ms | 115880 KiB |
| 02-07.txt | TLE | 2213 ms | 136960 KiB |
| 02-08.txt | TLE | 2218 ms | 227260 KiB |
| 02-09.txt | TLE | 2212 ms | 117300 KiB |
| 02-10.txt | TLE | 2212 ms | 102264 KiB |
| 03-01.txt | AC | 136 ms | 103704 KiB |
| 03-02.txt | AC | 156 ms | 135236 KiB |
| 03-03.txt | AC | 152 ms | 126940 KiB |
| 03-04.txt | TLE | 2212 ms | 114336 KiB |
| 03-05.txt | TLE | 2212 ms | 102664 KiB |
| 03-06.txt | TLE | 2214 ms | 139432 KiB |
| 03-07.txt | TLE | 2213 ms | 129272 KiB |
| hand-01.txt | TLE | 2257 ms | 994176 KiB |
| sample-01.txt | AC | 62 ms | 81820 KiB |