結果

問題 No.2686 商品券の使い道
ユーザー mymelochan
提出日時 2024-03-20 22:44:42
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 931 ms / 3,000 ms
コード長 1,063 bytes
コンパイル時間 690 ms
コンパイル使用メモリ 82,696 KB
実行使用メモリ 84,644 KB
最終ジャッジ日時 2024-09-30 08:51:13
合計ジャッジ時間 27,362 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 48
権限があれば一括ダウンロードができます

ソースコード

diff #

#############################################################

import sys
sys.setrecursionlimit(10**7)

from heapq import heappop,heappush
from collections import deque,defaultdict,Counter
from bisect import bisect_left, bisect_right
from itertools import product,combinations,permutations

ipt = sys.stdin.readline

def iin():
    return int(ipt())
def lmin():
    return list(map(int,ipt().split()))

MOD = 998244353
#############################################################

N,M,Q = lmin()
L = [lmin() for _ in range(N)]
pre = [0]*(1<<N)
for i in range(1,1<<N):
    v = 0
    p = 0
    for j in range(N):
        if i&(1<<j):
            v += L[j][1]
            p += L[j][0]
    
    if p <= Q:
        pre[i] = v
    
    for j in range(N):
        if not i&(1<<j):
            pre[i^(1<<j)] = max(pre[i^(1<<j)], pre[i])


ans = 0
for i in range(1<<N):
    v,p = 0,0
    for j in range(N):
        if i&(1<<j):
            v += L[j][1]
            p += L[j][0]
    
    if p <= M:
        c = ((1<<N)-1)^i
        ans = max(ans,v+pre[c])

print(ans)
    
0