結果

問題 No.2741 Balanced Choice
ユーザー t33ft33f
提出日時 2024-04-21 12:17:31
言語 Rust
(1.77.0)
結果
AC  
実行時間 66 ms / 2,000 ms
コード長 698 bytes
コンパイル時間 1,639 ms
コンパイル使用メモリ 163,840 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 12:17:34
合計ジャッジ時間 2,564 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
5,248 KB
testcase_01 AC 54 ms
5,376 KB
testcase_02 AC 59 ms
5,376 KB
testcase_03 AC 66 ms
5,376 KB
testcase_04 AC 65 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 16 ms
5,376 KB
testcase_08 AC 29 ms
5,376 KB
testcase_09 AC 15 ms
5,376 KB
testcase_10 AC 19 ms
5,376 KB
testcase_11 AC 29 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#![allow(non_snake_case)]
use proconio::{input};

fn main() {
    input!{
        n: usize, W: usize, D: usize,
        items: [(usize, usize, i32); n]
    }
    let mut value = vec![vec![i32::MIN; W + 1]; 2];
    value[0][0] = 0;
    value[1][0] = 0;
    for (t, w, v) in items {
        if w > W { continue; }
        for x in (0..=(W - w)).rev() {
            value[t][x + w] = value[t][x + w].max(value[t][x] + v);
        }
    }

    let mut ans = 0;
    for x in 0..=W {
        for y in 0..=(W - x) {
            if x.abs_diff(y) <= D && value[0][x] >= 0 && value[1][y] >= 0 {
                ans = ans.max(value[0][x] + value[1][y]);
            }
        }
    }
    println!("{ans}");
}
0