結果

問題 No.3683 サーバー代がもったいない!
コンテスト
ユーザー urectanc
提出日時 2026-09-05 13:49:07
言語 Rust
(1.97.1 + proconio + num + itertools)
コンパイル:
/usr/bin/rustc_custom
実行:
./target/release/main
結果
AC  
実行時間 20 ms / 2,000 ms
+ 134µs
コード長 810 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 16,059 ms
コンパイル使用メモリ 191,264 KB
実行使用メモリ 9,784 KB
最終ジャッジ日時 2026-09-05 13:52:27
合計ジャッジ時間 4,373 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

use proconio::input;

fn main() {
    input! {
        n: usize, k: usize,
        a: [i64; n],
    }

    let inf = 1i64 << 60;
    let mut dp = vec![[-inf; 2]; k + 1];
    dp[0][0] = 0;

    for &a in &a {
        let mut ndp = vec![[-inf; 2]; k + 1];
        for i in 0..=k {
            for j in 0..2 {
                if dp[i][j] == -inf {
                    continue;
                }
                if i < k && j == 0 {
                    let cand = dp[i][j] + a;
                    ndp[i + 1][1] = ndp[i + 1][1].max(cand);
                }
                ndp[i][0] = ndp[i][0].max(dp[i][j]);
            }
        }

        dp = ndp;
    }

    let ans = dp[k].iter().copied().max().unwrap();
    if ans == -inf {
        println!("Impossible");
    } else {
        println!("{ans}");
    }
}
0