結果

問題 No.2028 Even Choice
ユーザー phsplsphspls
提出日時 2022-09-28 10:52:29
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 1,029 bytes
コンパイル時間 1,893 ms
コンパイル使用メモリ 142,140 KB
実行使用メモリ 7,416 KB
最終ジャッジ日時 2023-08-24 04:19:55
合計ジャッジ時間 2,794 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 15 ms
7,416 KB
testcase_04 AC 17 ms
7,156 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 1 ms
4,380 KB
testcase_25 WA -
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::{collections::BinaryHeap, cmp::Reverse};


fn main() {
    let mut nk = String::new();
    std::io::stdin().read_line(&mut nk).ok();
    let nk: Vec<usize> = nk.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let n = nk[0];
    let k = nk[1];
    let mut a = String::new();
    std::io::stdin().read_line(&mut a).ok();
    let a: Vec<usize> = a.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();

    let mut pque = BinaryHeap::new();
    let mut result = 0usize;
    let mut summary = 0usize;
    for i in (1..n).rev() {
        if pque.len() < k {
            pque.push(Reverse(a[i]));
            summary += a[i];
            if i % 2 == 1 {
                result = summary;
            }
            continue;
        }
        let val = pque.peek().unwrap().0;
        if i % 2 == 1 {
            result = result.max(summary + a[i] - val);
        }
        pque.push(Reverse(a[i]));
        pque.pop();
        summary = summary + a[i] - val;
    }
    println!("{}", result);
}
0