結果

問題 No.2028 Even Choice
ユーザー phsplsphspls
提出日時 2022-09-28 10:53:55
言語 Rust
(1.77.0)
結果
AC  
実行時間 23 ms / 2,000 ms
コード長 1,050 bytes
コンパイル時間 10,845 ms
コンパイル使用メモリ 401,928 KB
実行使用メモリ 7,296 KB
最終ジャッジ日時 2024-06-02 01:27:06
合計ジャッジ時間 12,417 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 22 ms
6,816 KB
testcase_01 AC 19 ms
6,944 KB
testcase_02 AC 23 ms
6,940 KB
testcase_03 AC 15 ms
7,296 KB
testcase_04 AC 17 ms
6,948 KB
testcase_05 AC 5 ms
6,940 KB
testcase_06 AC 21 ms
6,944 KB
testcase_07 AC 6 ms
6,944 KB
testcase_08 AC 14 ms
6,940 KB
testcase_09 AC 14 ms
6,944 KB
testcase_10 AC 5 ms
6,948 KB
testcase_11 AC 4 ms
6,940 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 14 ms
6,940 KB
testcase_14 AC 7 ms
6,944 KB
testcase_15 AC 1 ms
6,944 KB
testcase_16 AC 0 ms
6,944 KB
testcase_17 AC 1 ms
6,944 KB
testcase_18 AC 1 ms
6,940 KB
testcase_19 AC 0 ms
6,940 KB
testcase_20 AC 1 ms
6,940 KB
testcase_21 AC 1 ms
6,940 KB
testcase_22 AC 1 ms
6,944 KB
testcase_23 AC 0 ms
6,940 KB
testcase_24 AC 1 ms
6,940 KB
testcase_25 AC 1 ms
6,944 KB
testcase_26 AC 1 ms
6,940 KB
testcase_27 AC 1 ms
6,944 KB
testcase_28 AC 9 ms
6,944 KB
testcase_29 AC 6 ms
6,944 KB
testcase_30 AC 4 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

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]));
        let val = pque.pop().unwrap().0;
        summary = summary + a[i] - val;
    }
    println!("{}", result);
}
0