結果

問題 No.2686 商品券の使い道
ユーザー Yakumo221Yakumo221
提出日時 2024-03-20 23:33:37
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,988 bytes
コンパイル時間 181 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 193,196 KB
最終ジャッジ日時 2024-03-20 23:34:37
合計ジャッジ時間 58,357 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 39 ms
53,460 KB
testcase_02 AC 517 ms
105,300 KB
testcase_03 AC 533 ms
107,516 KB
testcase_04 WA -
testcase_05 AC 531 ms
115,172 KB
testcase_06 AC 531 ms
103,444 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 485 ms
109,788 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 445 ms
104,956 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 451 ms
104,572 KB
testcase_21 AC 510 ms
110,936 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 529 ms
113,620 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 1,808 ms
187,732 KB
testcase_31 WA -
testcase_32 AC 2,033 ms
175,760 KB
testcase_33 AC 1,994 ms
188,808 KB
testcase_34 WA -
testcase_35 AC 1,991 ms
185,420 KB
testcase_36 WA -
testcase_37 WA -
testcase_38 AC 1,881 ms
179,304 KB
testcase_39 AC 1,968 ms
166,136 KB
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
evil_random20_1.txt WA -
evil_random20_2.txt WA -
evil_random20_3.txt AC 1,916 ms
183,644 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n, m, q = map(int, input().split())
# import sys
# input = sys.stdin.readline
# mp = map(int, sys.stdin.read().split())
# ab = list(zip(mp,mp))  

ab = []
for i in range(n):
    a,b = map(int, input().split())
    ab.append((a,b))

katidp = [[0 for i in range(1 << n)] for i in range(2)]
resdp = [[0 for i in range(1 << n)] for i in range(2)]
resdp[0][0] = m
resdp[1][0] = q

que = set([0])
for j in range(n):
    nq = set()
    while que:
        state = que.pop()
        mkati = katidp[0][state]
        qkati = katidp[1][state]
        mres = resdp[0][state]
        qres = resdp[1][state]

        for k in range(n):
            if state & (1 << k):
                continue
            else:
                nstate = state | (1 << k)
                nq.add(nstate)
                kati = ab[k][1]
                val = ab[k][0]


                if mres < val:
                    nres = mres
                    nkati = mkati
                else:
                    nkati = mkati + kati
                    nres = mres - val

                if katidp[0][nstate] < nkati:
                    katidp[0][nstate] = nkati
                    resdp[0][nstate] = nres
                elif katidp[0][nstate] == nkati:
                    if resdp[0][nstate] < nres:
                        resdp[0][nstate] = nres
                
                if qres < val:
                    nres = qres
                    nkati = mkati
                else:
                    nkati = mkati + kati
                    nres = qres - val

                if katidp[1][nstate] < nkati:
                    katidp[1][nstate] = nkati
                    resdp[1][nstate] = nres
                elif katidp[1][nstate] == nkati:
                    if resdp[1][nstate] < nres:
                        resdp[1][nstate] = nres
    que = nq

    # print(katidp)

mask = (1 << n) - 1

ans = 0
for i in range(1 << n):
    j = mask ^ i

    ans = max(ans, katidp[0][i] + katidp[1][j])

print(ans)
    



0