結果
問題 | No.2741 Balanced Choice |
ユーザー |
![]() |
提出日時 | 2024-04-29 20:31:04 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 59 ms / 2,000 ms |
コード長 | 1,157 bytes |
コンパイル時間 | 13,126 ms |
コンパイル使用メモリ | 378,224 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-19 03:41:32 |
合計ジャッジ時間 | 14,623 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 10 |
ソースコード
use std::str::FromStr; use std::{io::*, vec}; fn main() { let n: usize = read(); let w: usize = read(); let d: usize = read(); let mut value = vec![vec![i32::MIN; w + 1]; 2]; value[0][0] = 0; value[1][0] = 0; for _i in 1..=n { let ti: usize = read(); let wi: usize = read(); let vi: usize = read(); if wi > w{ continue; } for x in (0..=(w - wi)).rev(){ value[ti][x + wi] = value[ti][x + wi].max(value[ti][x] + vi as i32); } } 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); } pub fn read<T: FromStr>() -> T { let stdin = stdin(); let stdin = stdin.lock(); let token: String = stdin .bytes() .map(|c| c.expect("failed to read char") as char) .skip_while(|c| c.is_whitespace()) .take_while(|c| !c.is_whitespace()) .collect(); token.parse().ok().expect("failed to parse token") }