結果

問題 No.798 コレクション
ユーザー nebukuro09nebukuro09
提出日時 2019-03-15 22:38:32
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 29 ms / 2,000 ms
コード長 753 bytes
コンパイル時間 708 ms
コンパイル使用メモリ 112,984 KB
実行使用メモリ 28,032 KB
最終ジャッジ日時 2023-09-03 23:43:46
合計ジャッジ時間 2,690 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 13 ms
13,392 KB
testcase_14 AC 21 ms
23,108 KB
testcase_15 AC 19 ms
23,216 KB
testcase_16 AC 11 ms
11,628 KB
testcase_17 AC 13 ms
13,608 KB
testcase_18 AC 28 ms
28,032 KB
testcase_19 AC 23 ms
23,660 KB
testcase_20 AC 11 ms
12,620 KB
testcase_21 AC 10 ms
11,096 KB
testcase_22 AC 20 ms
22,220 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 28 ms
27,552 KB
testcase_25 AC 29 ms
28,032 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.string;

void main() {
    auto N = readln.chomp.to!int;
    auto AB = N.iota.map!(_ => readln.split.map!(to!long).array).array;
    AB.sort!"a[1] > b[1]";

    int buy = N - N / 3;

    auto dp = new long[][](N+1, buy+1);
    foreach (i; 0..N+1) dp[i][] = 1L << 59;
    dp[0][0] = 0;

    foreach (i; 0..N) {
        foreach (j; 0..buy+1) {
            if (j < buy) {
                dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j] + AB[i][0] + AB[i][1] * j);
            }
            dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
        }
    }

    dp[N][buy].writeln;
}
0