結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
71,352 KB
testcase_01 RE -
testcase_02 AC 66 ms
71,284 KB
testcase_03 AC 68 ms
71,236 KB
testcase_04 RE -
testcase_05 AC 67 ms
71,396 KB
testcase_06 AC 68 ms
71,520 KB
testcase_07 AC 66 ms
71,444 KB
testcase_08 AC 64 ms
71,424 KB
testcase_09 AC 66 ms
71,384 KB
testcase_10 AC 65 ms
71,480 KB
testcase_11 AC 68 ms
71,520 KB
testcase_12 AC 69 ms
71,404 KB
testcase_13 AC 130 ms
78,200 KB
testcase_14 AC 152 ms
78,432 KB
testcase_15 AC 146 ms
78,340 KB
testcase_16 AC 103 ms
77,644 KB
testcase_17 AC 132 ms
78,092 KB
testcase_18 AC 173 ms
78,408 KB
testcase_19 AC 161 ms
78,352 KB
testcase_20 AC 120 ms
77,700 KB
testcase_21 AC 120 ms
77,428 KB
testcase_22 AC 153 ms
78,568 KB
testcase_23 RE -
testcase_24 AC 141 ms
78,024 KB
testcase_25 AC 172 ms
78,264 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*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