結果

問題 No.951 【本日限定】1枚頼むともう1枚無料!
ユーザー nebukuro09nebukuro09
提出日時 2019-12-17 03:15:32
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 238 ms / 2,000 ms
コード長 1,161 bytes
コンパイル時間 1,163 ms
コンパイル使用メモリ 111,384 KB
実行使用メモリ 5,316 KB
最終ジャッジ日時 2023-09-04 04:07:37
合計ジャッジ時間 8,808 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 8 ms
4,376 KB
testcase_10 AC 5 ms
4,376 KB
testcase_11 AC 5 ms
4,380 KB
testcase_12 AC 50 ms
4,380 KB
testcase_13 AC 167 ms
4,376 KB
testcase_14 AC 29 ms
4,376 KB
testcase_15 AC 27 ms
4,376 KB
testcase_16 AC 41 ms
4,376 KB
testcase_17 AC 51 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 5 ms
4,376 KB
testcase_22 AC 3 ms
4,380 KB
testcase_23 AC 3 ms
4,376 KB
testcase_24 AC 235 ms
4,376 KB
testcase_25 AC 238 ms
4,380 KB
testcase_26 AC 231 ms
4,376 KB
testcase_27 AC 233 ms
4,376 KB
testcase_28 AC 207 ms
4,376 KB
testcase_29 AC 209 ms
4,376 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 3 ms
4,384 KB
testcase_33 AC 4 ms
4,376 KB
testcase_34 AC 7 ms
4,376 KB
testcase_35 AC 232 ms
4,376 KB
testcase_36 AC 232 ms
4,376 KB
testcase_37 AC 231 ms
5,316 KB
testcase_38 AC 232 ms
4,380 KB
testcase_39 AC 235 ms
4,380 KB
testcase_40 AC 228 ms
4,376 KB
testcase_41 AC 228 ms
4,376 KB
testcase_42 AC 232 ms
4,376 KB
testcase_43 AC 233 ms
4,376 KB
testcase_44 AC 232 ms
4,376 KB
testcase_45 AC 232 ms
4,376 KB
testcase_46 AC 213 ms
4,380 KB
testcase_47 AC 212 ms
4,380 KB
testcase_48 AC 210 ms
4,376 KB
testcase_49 AC 210 ms
4,376 KB
testcase_50 AC 208 ms
4,376 KB
testcase_51 AC 210 ms
4,376 KB
testcase_52 AC 187 ms
4,380 KB
testcase_53 AC 232 ms
4,376 KB
testcase_54 AC 179 ms
4,380 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;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto M = s[1];
    auto A = iota(N).map!(_ => readln.split.map!(to!int).array).array;
    A.sort!"a[0] > b[0]";

    auto dp = new int[][][](2, M+1, 2);
    foreach (i; 0..2) foreach (j; 0..M+1) dp[i][j][1] = -(1 << 29);

    int cur = 0;
    int tar = 1;

    foreach (i; 0..N) {
        int p = A[i][0];
        int d = A[i][1];
        foreach (j; 0..M+1) {
            dp[tar][j][0] = 0;
            dp[tar][j][1] = -(1 << 29);
        }
        foreach (j; 0..M+1) {
            dp[tar][j][0] = max(dp[tar][j][0], dp[cur][j][0]);
            dp[tar][j][1] = max(dp[tar][j][1], dp[cur][j][1]);
            if (p + j <= M) dp[tar][j+p][1] = max(dp[tar][j+p][1], dp[cur][j][0] + d);
            dp[tar][j][0] = max(dp[tar][j][0], dp[cur][j][1] + d);
        }
        swap(cur, tar);
    }

    int ans = 0;
    foreach (j; 0..M+1) foreach (k; 0..2) ans = max(ans, dp[cur][j][k]);
    ans.writeln;
}


0