結果

問題 No.798 コレクション
ユーザー pasoconhoshiipasoconhoshii
提出日時 2019-03-16 10:52:05
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 236 ms / 2,000 ms
コード長 548 bytes
コンパイル時間 270 ms
コンパイル使用メモリ 86,980 KB
実行使用メモリ 102,448 KB
最終ジャッジ日時 2023-09-14 15:07:30
合計ジャッジ時間 4,494 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,180 KB
testcase_01 AC 70 ms
71,124 KB
testcase_02 AC 70 ms
71,144 KB
testcase_03 AC 70 ms
71,460 KB
testcase_04 AC 76 ms
71,120 KB
testcase_05 AC 69 ms
71,128 KB
testcase_06 AC 70 ms
71,260 KB
testcase_07 AC 71 ms
71,524 KB
testcase_08 AC 70 ms
71,228 KB
testcase_09 AC 71 ms
71,344 KB
testcase_10 AC 71 ms
71,296 KB
testcase_11 AC 71 ms
71,044 KB
testcase_12 AC 70 ms
71,400 KB
testcase_13 AC 151 ms
80,884 KB
testcase_14 AC 187 ms
100,404 KB
testcase_15 AC 173 ms
97,008 KB
testcase_16 AC 132 ms
85,300 KB
testcase_17 AC 150 ms
80,668 KB
testcase_18 AC 206 ms
102,448 KB
testcase_19 AC 193 ms
101,556 KB
testcase_20 AC 134 ms
85,156 KB
testcase_21 AC 124 ms
85,192 KB
testcase_22 AC 177 ms
96,980 KB
testcase_23 AC 70 ms
71,176 KB
testcase_24 AC 236 ms
102,388 KB
testcase_25 AC 233 ms
102,104 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
AB = [ tuple([int(j) for j in input().split()]) for _ in range(N)]
AB = sorted(AB, key=lambda x:x[1], reverse=True)

dp = [ [ 10**12 ]*(N+1) for _ in range(N+1)] # i,j iコメまで集めて、j 個タダでもらった
dp[0][0] = 0

for i in range(1,N+1):
    for j in range(0,N):
        dp[i][j] = min ( dp[i][j], dp[i-1][j] + AB[i-1][0] + AB[i-1][1]* (i-j-1))   
        dp[i][j+1] = min( dp[i-1][j], dp[i][j+1]) # タダで買う
    dp[i][N] = min(dp[i][N], dp[i-1][N] + AB[i-1][0] + AB[i-1][1]*(i-j-1))


print(dp[N][N//3])
0