結果

問題 No.54 Happy Hallowe'en
ユーザー nebukuro09
提出日時 2017-06-14 11:11:38
言語 D
(dmd 2.109.1)
結果
AC  
実行時間 139 ms / 5,000 ms
コード長 834 bytes
コンパイル時間 708 ms
コンパイル使用メモリ 129,564 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-06-12 20:03:08
合計ジャッジ時間 1,970 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

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.stdio;

alias Tuple!(int, "v", int, "t") Okashi;

void main() {
    auto N = readln.chomp.to!int;
    auto K = new Okashi[](N);
    foreach (i; 0..N) {
        auto s = readln.split.map!(to!int);
        K[i] = Okashi(s[0], s[1]);
    }
    K.sort!"a.v + a.t < b.v + b.t"();

    auto dp = new bool[](10001);
    dp[0] = true;

    int ans = 0;
    
    foreach (i; 0..N) {
        foreach (j; iota(K[i].t-1, -1, -1)) {
            if (dp[j]) {
                ans = max(ans, j + K[i].v);
                if (j + K[i].v <= 10000) {
                    dp[j + K[i].v] = true;
                } 
            }
        }
    }


    ans.writeln;
}
0