結果

問題 No.2686 商品券の使い道
ユーザー とりゐとりゐ
提出日時 2024-03-20 22:37:57
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 981 ms / 3,000 ms
コード長 567 bytes
コンパイル時間 171 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 83,652 KB
最終ジャッジ日時 2024-03-20 22:38:29
合計ジャッジ時間 27,702 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,460 KB
testcase_01 AC 39 ms
53,460 KB
testcase_02 AC 222 ms
77,380 KB
testcase_03 AC 225 ms
77,380 KB
testcase_04 AC 223 ms
77,380 KB
testcase_05 AC 221 ms
77,380 KB
testcase_06 AC 221 ms
77,380 KB
testcase_07 AC 222 ms
77,380 KB
testcase_08 AC 222 ms
77,380 KB
testcase_09 AC 229 ms
77,388 KB
testcase_10 AC 222 ms
77,380 KB
testcase_11 AC 223 ms
77,388 KB
testcase_12 AC 225 ms
77,388 KB
testcase_13 AC 228 ms
77,384 KB
testcase_14 AC 226 ms
77,388 KB
testcase_15 AC 236 ms
77,388 KB
testcase_16 AC 227 ms
77,388 KB
testcase_17 AC 226 ms
77,388 KB
testcase_18 AC 239 ms
77,388 KB
testcase_19 AC 237 ms
77,388 KB
testcase_20 AC 222 ms
77,376 KB
testcase_21 AC 230 ms
77,504 KB
testcase_22 AC 236 ms
77,388 KB
testcase_23 AC 230 ms
77,388 KB
testcase_24 AC 232 ms
77,388 KB
testcase_25 AC 225 ms
77,388 KB
testcase_26 AC 237 ms
77,388 KB
testcase_27 AC 223 ms
77,376 KB
testcase_28 AC 251 ms
77,368 KB
testcase_29 AC 947 ms
83,652 KB
testcase_30 AC 972 ms
83,652 KB
testcase_31 AC 958 ms
83,652 KB
testcase_32 AC 918 ms
83,652 KB
testcase_33 AC 915 ms
83,652 KB
testcase_34 AC 958 ms
83,652 KB
testcase_35 AC 981 ms
83,652 KB
testcase_36 AC 950 ms
83,652 KB
testcase_37 AC 922 ms
83,652 KB
testcase_38 AC 934 ms
83,652 KB
testcase_39 AC 942 ms
83,652 KB
testcase_40 AC 933 ms
83,652 KB
testcase_41 AC 909 ms
83,652 KB
testcase_42 AC 911 ms
83,652 KB
testcase_43 AC 925 ms
83,652 KB
testcase_44 AC 940 ms
83,652 KB
testcase_45 AC 914 ms
83,652 KB
testcase_46 AC 940 ms
83,652 KB
evil_random20_1.txt AC 911 ms
83,652 KB
evil_random20_2.txt AC 907 ms
83,652 KB
evil_random20_3.txt AC 873 ms
83,652 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

dp=[0]*(1<<n)
for bit in range(1<<n):
  cost=0
  val=0
  for i in range(n):
    if (bit>>i)&1:
      cost+=ab[i][0]
      val+=ab[i][1]
  if cost<=m:
    dp[bit]=val
  for i in range(n):
    if (bit>>i)&1==0:
      dp[bit|(1<<i)]=max(dp[bit|(1<<i)],dp[bit])

mask=(1<<n)-1
ans=0
for bit in range(1<<n):
  cost=0
  val=0
  for i in range(n):
    if (bit>>i)&1:
      cost+=ab[i][0]
      val+=ab[i][1]
  if cost<=q:
    ans=max(ans,val+dp[bit^mask])

print(ans)
0