結果

問題 No.798 コレクション
ユーザー tktk_snsntktk_snsn
提出日時 2020-06-18 21:58:44
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 720 bytes
コンパイル時間 1,009 ms
コンパイル使用メモリ 86,740 KB
実行使用メモリ 100,636 KB
最終ジャッジ日時 2023-09-16 12:22:11
合計ジャッジ時間 5,307 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,444 KB
testcase_01 AC 74 ms
71,152 KB
testcase_02 AC 73 ms
71,320 KB
testcase_03 AC 73 ms
71,348 KB
testcase_04 AC 72 ms
71,348 KB
testcase_05 AC 72 ms
71,372 KB
testcase_06 AC 73 ms
71,308 KB
testcase_07 AC 73 ms
71,052 KB
testcase_08 AC 75 ms
71,200 KB
testcase_09 AC 73 ms
71,504 KB
testcase_10 AC 73 ms
71,380 KB
testcase_11 AC 73 ms
71,236 KB
testcase_12 AC 73 ms
71,284 KB
testcase_13 AC 129 ms
78,520 KB
testcase_14 AC 156 ms
100,128 KB
testcase_15 AC 146 ms
96,968 KB
testcase_16 AC 119 ms
82,916 KB
testcase_17 AC 129 ms
78,472 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 120 ms
82,800 KB
testcase_21 AC 116 ms
83,508 KB
testcase_22 WA -
testcase_23 AC 74 ms
71,316 KB
testcase_24 AC 160 ms
100,116 KB
testcase_25 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

from operator import itemgetter
N = int(input())
AB = [list(map(int, input().split())) for _ in range(N)]
AB.sort(key=itemgetter(1), reverse=True)

d, m = divmod(N, 3)
X = 2 * d + m  # 購入するのはX個、N-Xはキャンペーンで購入できる。

# dp[i][j]: iこ目の商品を見てる。これまでj個商品を無視.
# N-Xこ無視したときの費用の最小値が答え
inf = 10 ** 10
dp = [[inf] * (N + 5) for _ in range(N + 5)]
dp[0][0] = 0

for i, (a, b) in enumerate(AB):
    for j in range(i + 1):
        cost = a + b * (i - j)
        dp[i+1][j] = min(dp[i+1][j], dp[i][j]+cost)  # 商品を購入する
        dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j])  # 購入しない,

print(dp[N][N-X])
0