結果

問題 No.798 コレクション
ユーザー shotoyoo
提出日時 2021-07-22 14:48:31
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 98 ms / 2,000 ms
コード長 652 bytes
コンパイル時間 310 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 76,824 KB
最終ジャッジ日時 2024-07-17 14:46:02
合計ジャッジ時間 2,782 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda : sys.stdin.readline().rstrip()

sys.setrecursionlimit(2*10**5+10)
write = lambda x: sys.stdout.write(x+"\n")
debug = lambda x: sys.stderr.write(x+"\n")
writef = lambda x: print("{:.12f}".format(x))


n = int(input())
ab = [list(map(int, input().split())) for _ in range(n)]
index = list(range(n))
index.sort(key=lambda i : -ab[i][1])
inf = 10**12
dp = [inf]*(n+1)
dp[0] = 0
for ind in index:
    a,b = ab[ind]
    ndp = dp[:]
    for i in range(n):
        val = dp[i]
        if val==inf:
            continue
        ndp[i+1] = min(ndp[i+1], val+a+b*i)
    dp = ndp
#     print(dp)
v = (n//3)*2 + n%3
ans = dp[v]
print(ans)
0