結果

問題 No.798 コレクション
ユーザー tktk_snsntktk_snsn
提出日時 2020-06-18 21:57:58
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 720 bytes
コンパイル時間 175 ms
コンパイル使用メモリ 10,772 KB
実行使用メモリ 82,884 KB
最終ジャッジ日時 2023-09-16 12:26:21
合計ジャッジ時間 22,246 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,776 KB
testcase_01 AC 16 ms
7,776 KB
testcase_02 AC 17 ms
7,796 KB
testcase_03 AC 16 ms
7,920 KB
testcase_04 AC 17 ms
7,864 KB
testcase_05 AC 16 ms
7,780 KB
testcase_06 AC 16 ms
7,868 KB
testcase_07 AC 16 ms
7,864 KB
testcase_08 AC 17 ms
7,804 KB
testcase_09 AC 16 ms
7,848 KB
testcase_10 AC 17 ms
7,960 KB
testcase_11 AC 16 ms
7,780 KB
testcase_12 AC 16 ms
7,820 KB
testcase_13 AC 1,215 ms
51,664 KB
testcase_14 AC 1,976 ms
81,320 KB
testcase_15 AC 1,732 ms
70,060 KB
testcase_16 AC 783 ms
34,948 KB
testcase_17 AC 1,270 ms
53,632 KB
testcase_18 TLE -
testcase_19 TLE -
testcase_20 AC 839 ms
37,328 KB
testcase_21 AC 737 ms
34,292 KB
testcase_22 WA -
testcase_23 AC 16 ms
7,772 KB
testcase_24 TLE -
testcase_25 TLE -
権限があれば一括ダウンロードができます

ソースコード

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