結果

問題 No.798 コレクション
ユーザー persimmon-persimmonpersimmon-persimmon
提出日時 2021-06-30 17:30:02
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 179 ms / 2,000 ms
コード長 627 bytes
コンパイル時間 584 ms
コンパイル使用メモリ 86,808 KB
実行使用メモリ 78,344 KB
最終ジャッジ日時 2023-09-09 10:31:11
合計ジャッジ時間 4,779 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,176 KB
testcase_01 AC 72 ms
71,340 KB
testcase_02 AC 72 ms
71,248 KB
testcase_03 AC 72 ms
71,292 KB
testcase_04 AC 72 ms
71,300 KB
testcase_05 AC 72 ms
71,112 KB
testcase_06 AC 70 ms
71,168 KB
testcase_07 AC 72 ms
71,176 KB
testcase_08 AC 71 ms
71,280 KB
testcase_09 AC 69 ms
71,020 KB
testcase_10 AC 70 ms
71,372 KB
testcase_11 AC 72 ms
71,076 KB
testcase_12 AC 73 ms
71,452 KB
testcase_13 AC 138 ms
77,888 KB
testcase_14 AC 160 ms
78,100 KB
testcase_15 AC 153 ms
78,340 KB
testcase_16 AC 112 ms
77,412 KB
testcase_17 AC 138 ms
77,812 KB
testcase_18 AC 179 ms
78,128 KB
testcase_19 AC 165 ms
78,088 KB
testcase_20 AC 126 ms
77,544 KB
testcase_21 AC 121 ms
77,404 KB
testcase_22 AC 157 ms
78,344 KB
testcase_23 AC 71 ms
71,456 KB
testcase_24 AC 149 ms
77,792 KB
testcase_25 AC 179 ms
77,808 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+1)
  # dp[j]商品iまででj個買うときの最小
  dp[0]=0
  for i in range(n):
    ndp=dp[:]
    a,b=ab[i]
    for j in range(n):
      if dp[j]==inf:continue
      ndp[j+1]=min(ndp[j+1],dp[j]+a+b*j)
    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