結果

問題 No.798 コレクション
ユーザー persimmon-persimmonpersimmon-persimmon
提出日時 2021-06-30 17:24:24
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 625 bytes
コンパイル時間 631 ms
コンパイル使用メモリ 87,140 KB
実行使用メモリ 79,124 KB
最終ジャッジ日時 2023-09-09 10:25:26
合計ジャッジ時間 4,776 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 RE -
testcase_02 WA -
testcase_03 AC 65 ms
71,348 KB
testcase_04 RE -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 RE -
testcase_24 AC 137 ms
77,860 KB
testcase_25 AC 169 ms
78,200 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def main1(n,ab):
  k=0
  cnt=0
  for i in range(n):
      cnt+=1
      if i%2==1:
          cnt+=1
      if cnt>=n:
          k=i+1
          break
  # k個の商品を買う
  ab.sort(key=lambda x:x[1],reverse=True)
  inf=float('inf')
  dp=[inf]*n
  # dp[j]商品iまででj個買うときの最小
  dp[0]=0
  for i in range(n):
    ndp=dp[:]
    a,b=ab[i]
    for j in range(n-1):
      if dp[j]==inf:continue
      ndp[j+1]=min(ndp[j+1],dp[j]+a+b*i)
    dp=ndp
  return dp[k]
    

if __name__=='__main__':
    n=int(input())
    ab=[list(map(int,input().split())) for _ in range(n)]
    ret1=main1(n,ab)
    print(ret1)
0