結果

問題 No.2686 商品券の使い道
ユーザー ShirotsumeShirotsume
提出日時 2024-03-20 21:24:44
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,583 ms / 3,000 ms
コード長 1,179 bytes
コンパイル時間 638 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 93,264 KB
最終ジャッジ日時 2024-03-20 21:25:27
合計ジャッジ時間 42,912 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
56,268 KB
testcase_01 AC 48 ms
56,268 KB
testcase_02 AC 285 ms
80,844 KB
testcase_03 AC 297 ms
80,984 KB
testcase_04 AC 304 ms
80,984 KB
testcase_05 AC 287 ms
80,844 KB
testcase_06 AC 289 ms
80,844 KB
testcase_07 AC 295 ms
80,856 KB
testcase_08 AC 282 ms
80,844 KB
testcase_09 AC 292 ms
80,984 KB
testcase_10 AC 295 ms
80,984 KB
testcase_11 AC 325 ms
80,984 KB
testcase_12 AC 296 ms
80,984 KB
testcase_13 AC 282 ms
80,856 KB
testcase_14 AC 296 ms
80,984 KB
testcase_15 AC 330 ms
80,984 KB
testcase_16 AC 288 ms
80,984 KB
testcase_17 AC 306 ms
80,984 KB
testcase_18 AC 294 ms
80,984 KB
testcase_19 AC 322 ms
80,984 KB
testcase_20 AC 275 ms
80,848 KB
testcase_21 AC 289 ms
80,984 KB
testcase_22 AC 299 ms
80,984 KB
testcase_23 AC 312 ms
80,984 KB
testcase_24 AC 294 ms
80,984 KB
testcase_25 AC 301 ms
80,984 KB
testcase_26 AC 297 ms
80,984 KB
testcase_27 AC 278 ms
80,848 KB
testcase_28 AC 280 ms
80,844 KB
testcase_29 AC 1,568 ms
93,128 KB
testcase_30 AC 1,505 ms
93,100 KB
testcase_31 AC 1,583 ms
93,128 KB
testcase_32 AC 1,526 ms
93,128 KB
testcase_33 AC 1,549 ms
93,100 KB
testcase_34 AC 1,536 ms
93,128 KB
testcase_35 AC 1,578 ms
93,100 KB
testcase_36 AC 1,557 ms
93,128 KB
testcase_37 AC 1,560 ms
93,128 KB
testcase_38 AC 1,518 ms
93,128 KB
testcase_39 AC 1,558 ms
93,128 KB
testcase_40 AC 1,563 ms
93,128 KB
testcase_41 AC 1,546 ms
93,104 KB
testcase_42 AC 1,579 ms
93,264 KB
testcase_43 AC 1,552 ms
93,128 KB
testcase_44 AC 1,543 ms
93,128 KB
testcase_45 AC 1,568 ms
93,256 KB
testcase_46 AC 1,542 ms
93,136 KB
evil_random20_1.txt AC 1,594 ms
93,112 KB
evil_random20_2.txt AC 1,565 ms
93,104 KB
evil_random20_3.txt AC 1,582 ms
93,104 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys, time, random
from collections import deque, Counter, defaultdict
input = lambda: sys.stdin.readline().rstrip()
ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(mi())
inf = 2 ** 63 - 1
mod = 998244353

n, m, q = mi()

AB = [li() for _ in range(20)]
before = [0] * (1 << n)
for bit in range(1 << n):
    value = 0
    weight = 0
    for i in range(n):
        if 1 & (bit >> i):
            value += AB[i][1]
            weight += AB[i][0]
    if weight <= m:
        before[bit] = value
for bit in range(1 << n):
    for i in range(n):
        if (1 & (bit >> i)):
            before[bit] = max(before[bit ^ (1 << i)], before[bit])
            
after = [0] * (1 << n)

for bit in range(1 << n):
    value = 0
    weight = 0
    for i in range(n):
        if 1 & (bit >> i):
            value += AB[i][1]
            weight += AB[i][0]
    if weight <= q:
        after[bit] = value

for bit in range(1 << n):
    for i in range(n):
        if (1 & (bit >> i)):
            after[bit] = max(after[bit - (1 << i)], after[bit])
ans = 0
for bit in range(1 << n):
    ans = max(ans, before[bit] + after[(1 << n) - 1 - bit])
print(ans)
    
0