結果
問題 | No.951 【本日限定】1枚頼むともう1枚無料! |
ユーザー |
![]() |
提出日時 | 2019-12-14 06:06:26 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 21 ms / 2,000 ms |
コード長 | 1,095 bytes |
コンパイル時間 | 18,985 ms |
コンパイル使用メモリ | 388,344 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-28 03:01:21 |
合計ジャッジ時間 | 21,458 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 52 |
ソースコード
use std::io::Read;fn run() {let mut s = String::new();std::io::stdin().read_to_string(&mut s).unwrap();let mut it = s.trim().split_whitespace();let n: usize = it.next().unwrap().parse().unwrap();let w: usize = it.next().unwrap().parse().unwrap();let mut p: Vec<(usize, i32)> = (0..n).map(|_| {let p: usize = it.next().unwrap().parse().unwrap();let d: i32 = it.next().unwrap().parse().unwrap();(p, d)}).collect();p.sort();let mut now = vec![vec![std::i32::MIN; w + 1]; 2];now[0] = vec![0; w + 1];let mut next = now.clone();for (p, d) in p.into_iter().rev() {next.clone_from(&now);for (next, now) in next[1][p..].iter_mut().zip(now[0].iter()) {*next = std::cmp::max(*next, *now + d);}for (next, now) in next[0].iter_mut().zip(now[1].iter()) {*next = std::cmp::max(*next, *now + d);}std::mem::swap(&mut now, &mut next);}let ans = std::cmp::max(now[0][w], now[1][w]);println!("{}", ans);}fn main() {run();}