結果

問題 No.798 コレクション
ユーザー brthyyjpbrthyyjp
提出日時 2022-02-06 16:36:51
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 149 ms / 2,000 ms
コード長 414 bytes
コンパイル時間 344 ms
コンパイル使用メモリ 87,004 KB
実行使用メモリ 77,820 KB
最終ジャッジ日時 2023-09-02 07:00:40
合計ジャッジ時間 4,683 ms
ジャッジサーバーID
(参考情報)
judge13 / judge16
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,240 KB
testcase_01 AC 73 ms
71,168 KB
testcase_02 AC 71 ms
71,312 KB
testcase_03 AC 74 ms
71,228 KB
testcase_04 AC 72 ms
71,228 KB
testcase_05 AC 72 ms
71,280 KB
testcase_06 AC 70 ms
71,116 KB
testcase_07 AC 70 ms
71,440 KB
testcase_08 AC 71 ms
71,300 KB
testcase_09 AC 71 ms
71,060 KB
testcase_10 AC 71 ms
71,444 KB
testcase_11 AC 70 ms
71,496 KB
testcase_12 AC 71 ms
71,236 KB
testcase_13 AC 120 ms
77,320 KB
testcase_14 AC 127 ms
77,684 KB
testcase_15 AC 123 ms
77,368 KB
testcase_16 AC 106 ms
77,004 KB
testcase_17 AC 116 ms
77,680 KB
testcase_18 AC 129 ms
77,820 KB
testcase_19 AC 123 ms
77,360 KB
testcase_20 AC 106 ms
77,188 KB
testcase_21 AC 101 ms
77,176 KB
testcase_22 AC 121 ms
77,344 KB
testcase_23 AC 71 ms
71,316 KB
testcase_24 AC 145 ms
77,704 KB
testcase_25 AC 149 ms
77,648 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
AB = []
for i in range(n):
    a, b = map(int, input().split())
    AB.append((a, b))
AB.sort(key=lambda x: -x[1])
INF = 10**18
dp = [INF]*(n+1)
dp[0] = 0
for i, (a, b) in enumerate(AB):
    nx = [INF]*(n+1)
    for j in range(n):
        if j >= 1:
            nx[j] = min(nx[j], dp[j-1], dp[j]+a+b*(i-j))
        else:
            nx[j] = min(nx[j], dp[j]+a+b*(i-j))
    dp = nx
print(dp[n//3])
0