結果
| 問題 | No.2922 Rose Garden | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2024-10-12 15:35:48 | 
| 言語 | Rust (1.83.0 + proconio) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 183 ms / 3,000 ms | 
| コード長 | 1,547 bytes | 
| コンパイル時間 | 13,144 ms | 
| コンパイル使用メモリ | 379,596 KB | 
| 実行使用メモリ | 5,504 KB | 
| 最終ジャッジ日時 | 2024-10-12 15:36:07 | 
| 合計ジャッジ時間 | 17,679 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 50 | 
ソースコード
use proconio::input;
fn main() {
    input! {
        (n, s, b): (usize, usize, usize),
        hh: [usize; n],
    }
    // dp[i]: スタミナがiのときの最高高度
    let mut dp = vec![None; s + 1];
    dp[s] = Some(hh[0]);
    let mut next_dp = vec![None; s + 1];
    for &h in &hh[1..] {
        for (stamina, &max_height) in dp.iter().enumerate() {
            let Some(max_height) = max_height else {
                continue;
            };
            let consumption = (h.saturating_sub(max_height) + b - 1) / b;
            if consumption <= stamina {
                chmax_for_option(
                    &mut next_dp[stamina - consumption],
                    max_height + b * consumption,
                );
                chmax_for_option(&mut next_dp[s], h);
            }
        }
        std::mem::swap(&mut dp, &mut next_dp);
        next_dp.fill(None);
    }
    let ans = dp.iter().any(|max_height| max_height.is_some());
    println!("{}", if ans { "Yes" } else { "No" });
}
/// If `value` is `None` or contains a value less than `cand_value`, update it to `Some(cand_value)`.
///
/// Returns whether `value` has been updated or not as a bool value.
///
/// # Arguments
///
/// * `value` - Reference variable to be updated.
/// * `cand_value` - Candidate value for update.
pub fn chmax_for_option<T>(value: &mut Option<T>, cand_value: T) -> bool
where
    T: PartialOrd,
{
    if value.as_ref().is_some_and(|cost| cost >= &cand_value) {
        return false;
    }
    *value = Some(cand_value);
    true
}
            
            
            
        