結果

問題 No.2686 商品券の使い道
ユーザー PNJPNJ
提出日時 2024-03-20 22:30:35
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,163 ms / 3,000 ms
コード長 631 bytes
コンパイル時間 272 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 83,752 KB
最終ジャッジ日時 2024-03-20 22:31:25
合計ジャッジ時間 32,249 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
53,460 KB
testcase_01 AC 38 ms
53,460 KB
testcase_02 AC 229 ms
77,604 KB
testcase_03 AC 221 ms
77,732 KB
testcase_04 AC 217 ms
77,604 KB
testcase_05 AC 210 ms
77,604 KB
testcase_06 AC 215 ms
77,476 KB
testcase_07 AC 250 ms
77,604 KB
testcase_08 AC 213 ms
77,604 KB
testcase_09 AC 223 ms
77,732 KB
testcase_10 AC 218 ms
77,604 KB
testcase_11 AC 216 ms
77,732 KB
testcase_12 AC 244 ms
77,732 KB
testcase_13 AC 219 ms
77,604 KB
testcase_14 AC 215 ms
77,732 KB
testcase_15 AC 220 ms
77,732 KB
testcase_16 AC 219 ms
77,732 KB
testcase_17 AC 245 ms
77,732 KB
testcase_18 AC 221 ms
77,604 KB
testcase_19 AC 219 ms
77,732 KB
testcase_20 AC 212 ms
77,604 KB
testcase_21 AC 217 ms
77,732 KB
testcase_22 AC 222 ms
77,732 KB
testcase_23 AC 241 ms
77,604 KB
testcase_24 AC 224 ms
77,732 KB
testcase_25 AC 222 ms
77,732 KB
testcase_26 AC 219 ms
77,732 KB
testcase_27 AC 212 ms
77,604 KB
testcase_28 AC 222 ms
77,604 KB
testcase_29 AC 1,135 ms
83,624 KB
testcase_30 AC 1,125 ms
83,620 KB
testcase_31 AC 1,137 ms
83,624 KB
testcase_32 AC 1,147 ms
83,752 KB
testcase_33 AC 1,108 ms
83,620 KB
testcase_34 AC 1,132 ms
83,624 KB
testcase_35 AC 1,132 ms
83,620 KB
testcase_36 AC 1,160 ms
83,752 KB
testcase_37 AC 1,161 ms
83,752 KB
testcase_38 AC 1,124 ms
83,752 KB
testcase_39 AC 1,122 ms
83,752 KB
testcase_40 AC 1,144 ms
83,752 KB
testcase_41 AC 1,160 ms
83,620 KB
testcase_42 AC 1,163 ms
83,624 KB
testcase_43 AC 1,157 ms
83,752 KB
testcase_44 AC 1,133 ms
83,752 KB
testcase_45 AC 1,137 ms
83,624 KB
testcase_46 AC 1,158 ms
83,752 KB
evil_random20_1.txt AC 1,155 ms
83,620 KB
evil_random20_2.txt AC 1,162 ms
83,620 KB
evil_random20_3.txt AC 1,158 ms
83,620 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def Map():
  return list(map(int,input().split()))

N,M,Q = Map()
A,B = [0]*N,[0]*N
for i in range(N):
  A[i],B[i] = Map()

dp = [0 for i in range(1 << N)]

for j in range(1 << N):
  a,b = 0,0
  for i in range(N):
    if (j >> i) & 1:
      a += A[i]
      b += B[i]
  if a <= M:
    dp[j] = b

for j in range(1 << N):
  for i in range(N):
    if (j >> i) & 1:
      k = j ^ (1 << i)
      dp[j] = max(dp[j],dp[k])

ans = 0
mask = (1 << N) - 1
for j in range(1 << N):
  a,b = 0,0
  for i in range(N):
    if (j >> i) & 1:
      a += A[i]
      b += B[i]
  if a > Q:
    continue
  k = j ^ mask
  ans = max(ans,b + dp[k])
print(ans)
0