結果

問題 No.798 コレクション
ユーザー roarisroaris
提出日時 2020-12-02 23:41:59
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 203 ms / 2,000 ms
コード長 520 bytes
コンパイル時間 403 ms
コンパイル使用メモリ 87,216 KB
実行使用メモリ 109,516 KB
最終ジャッジ日時 2023-10-11 12:08:01
合計ジャッジ時間 5,226 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,636 KB
testcase_01 AC 72 ms
71,572 KB
testcase_02 AC 72 ms
71,388 KB
testcase_03 AC 75 ms
71,580 KB
testcase_04 AC 70 ms
71,288 KB
testcase_05 AC 71 ms
71,388 KB
testcase_06 AC 71 ms
71,624 KB
testcase_07 AC 72 ms
71,308 KB
testcase_08 AC 72 ms
71,416 KB
testcase_09 AC 72 ms
71,428 KB
testcase_10 AC 70 ms
71,628 KB
testcase_11 AC 70 ms
71,304 KB
testcase_12 AC 72 ms
71,360 KB
testcase_13 AC 151 ms
88,468 KB
testcase_14 AC 165 ms
87,828 KB
testcase_15 AC 158 ms
88,256 KB
testcase_16 AC 131 ms
86,448 KB
testcase_17 AC 146 ms
88,264 KB
testcase_18 AC 203 ms
107,676 KB
testcase_19 AC 169 ms
87,880 KB
testcase_20 AC 131 ms
87,192 KB
testcase_21 AC 120 ms
85,432 KB
testcase_22 AC 160 ms
87,812 KB
testcase_23 AC 73 ms
71,380 KB
testcase_24 AC 202 ms
109,384 KB
testcase_25 AC 201 ms
109,516 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

N = int(input())
AB = [tuple(map(int, input().split())) for _ in range(N)]
AB.sort(key=lambda t: t[1], reverse=True)
dp = [[10**18]*(N+1) for _ in range(N+1)]
dp[0][0] = 0

for i in range(N):
    A, B = AB[i]
    
    for j in range(N+1):
        dp[i+1][j] = min(dp[i+1][j], dp[i][j])
        
        if j+1<=N:
            dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j]+A+B*j)
    
ans = 10**18

for i in range(N+1):
    if i//2>=N-i:
        ans = min(ans, dp[N][i])
    
print(ans)
0