結果

問題 No.2686 商品券の使い道
ユーザー rlangevinrlangevin
提出日時 2024-03-24 19:04:27
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 693 ms / 3,000 ms
コード長 752 bytes
コンパイル時間 2,592 ms
コンパイル使用メモリ 81,444 KB
実行使用メモリ 91,812 KB
最終ジャッジ日時 2024-03-24 19:05:52
合計ジャッジ時間 27,974 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
53,460 KB
testcase_01 AC 34 ms
53,460 KB
testcase_02 AC 159 ms
79,632 KB
testcase_03 AC 161 ms
79,520 KB
testcase_04 AC 161 ms
79,520 KB
testcase_05 AC 161 ms
79,632 KB
testcase_06 AC 161 ms
79,632 KB
testcase_07 AC 161 ms
79,520 KB
testcase_08 AC 153 ms
79,632 KB
testcase_09 AC 161 ms
79,520 KB
testcase_10 AC 160 ms
79,520 KB
testcase_11 AC 166 ms
79,520 KB
testcase_12 AC 186 ms
79,524 KB
testcase_13 AC 158 ms
79,520 KB
testcase_14 AC 164 ms
79,520 KB
testcase_15 AC 167 ms
79,520 KB
testcase_16 AC 162 ms
79,524 KB
testcase_17 AC 167 ms
79,520 KB
testcase_18 AC 163 ms
79,524 KB
testcase_19 AC 161 ms
79,524 KB
testcase_20 AC 152 ms
77,720 KB
testcase_21 AC 158 ms
79,520 KB
testcase_22 AC 163 ms
79,520 KB
testcase_23 AC 185 ms
79,520 KB
testcase_24 AC 160 ms
79,520 KB
testcase_25 AC 172 ms
79,524 KB
testcase_26 AC 163 ms
79,524 KB
testcase_27 AC 165 ms
79,520 KB
testcase_28 AC 156 ms
79,520 KB
testcase_29 AC 675 ms
91,812 KB
testcase_30 AC 660 ms
91,680 KB
testcase_31 AC 664 ms
91,812 KB
testcase_32 AC 650 ms
91,808 KB
testcase_33 AC 673 ms
91,680 KB
testcase_34 AC 654 ms
91,808 KB
testcase_35 AC 663 ms
91,680 KB
testcase_36 AC 685 ms
91,680 KB
testcase_37 AC 664 ms
91,812 KB
testcase_38 AC 670 ms
91,680 KB
testcase_39 AC 651 ms
91,812 KB
testcase_40 AC 693 ms
91,812 KB
testcase_41 AC 635 ms
91,672 KB
testcase_42 AC 679 ms
91,812 KB
testcase_43 AC 689 ms
91,812 KB
testcase_44 AC 665 ms
91,812 KB
testcase_45 AC 692 ms
91,812 KB
testcase_46 AC 664 ms
91,812 KB
evil_random20_1.txt AC 660 ms
91,664 KB
evil_random20_2.txt AC 643 ms
91,668 KB
evil_random20_3.txt AC 666 ms
91,668 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

def zeta(A, N, op):
    for i in range(N):
        for bit in range(1 << N):
            if (bit & (1 << i)):
                A[bit] = op(A[bit], A[bit^(1<<i)])
    return A


N, M, Q = map(int, input().split())
A, B = [0] * N, [0] * N
for i in range(N):
    A[i], B[i] = map(int, input().split())
    
N2 = 1 << N
inf = 10 ** 18
dpM, dpQ = [-inf] * N2, [-inf] * N2
for s in range(N2):
    x, y = 0, 0
    for i in range(N):
        if (s >> i) & 1:
            x += A[i]
            y += B[i]
    if x <= M:
        dpM[s] = y
    if x <= Q:
        dpQ[s] = y
        
dpM = zeta(dpM, N, max)
dpQ = zeta(dpQ, N, max)
ans = 0
for s in range(N2):
    ans = max(ans, dpM[s] + dpQ[(N2 - 1) ^ s])
    
print(ans)    
0