結果

問題 No.798 コレクション
ユーザー shotoyooshotoyoo
提出日時 2021-07-22 14:48:31
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 129 ms / 2,000 ms
コード長 652 bytes
コンパイル時間 1,039 ms
コンパイル使用メモリ 86,924 KB
実行使用メモリ 77,680 KB
最終ジャッジ日時 2023-09-24 13:59:50
合計ジャッジ時間 4,891 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
70,816 KB
testcase_01 AC 75 ms
70,792 KB
testcase_02 AC 72 ms
71,264 KB
testcase_03 AC 73 ms
71,216 KB
testcase_04 AC 73 ms
71,316 KB
testcase_05 AC 75 ms
71,244 KB
testcase_06 AC 72 ms
71,328 KB
testcase_07 AC 74 ms
71,304 KB
testcase_08 AC 74 ms
70,924 KB
testcase_09 AC 74 ms
71,336 KB
testcase_10 AC 74 ms
71,216 KB
testcase_11 AC 74 ms
71,184 KB
testcase_12 AC 75 ms
71,312 KB
testcase_13 AC 128 ms
77,372 KB
testcase_14 AC 122 ms
77,608 KB
testcase_15 AC 118 ms
77,460 KB
testcase_16 AC 103 ms
77,072 KB
testcase_17 AC 113 ms
77,380 KB
testcase_18 AC 129 ms
77,664 KB
testcase_19 AC 122 ms
77,432 KB
testcase_20 AC 102 ms
77,292 KB
testcase_21 AC 98 ms
77,188 KB
testcase_22 AC 118 ms
77,680 KB
testcase_23 AC 74 ms
71,328 KB
testcase_24 AC 125 ms
77,512 KB
testcase_25 AC 127 ms
77,632 KB
権限があれば一括ダウンロードができます

ソースコード

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