結果

問題 No.2028 Even Choice
ユーザー phsplsphspls
提出日時 2022-09-14 23:20:08
言語 Rust
(1.77.0)
結果
AC  
実行時間 27 ms / 2,000 ms
コード長 1,032 bytes
コンパイル時間 4,905 ms
コンパイル使用メモリ 137,984 KB
実行使用メモリ 7,432 KB
最終ジャッジ日時 2023-08-21 20:56:23
合計ジャッジ時間 4,818 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
6,440 KB
testcase_01 AC 23 ms
6,628 KB
testcase_02 AC 27 ms
6,120 KB
testcase_03 AC 15 ms
7,432 KB
testcase_04 AC 18 ms
7,168 KB
testcase_05 AC 5 ms
4,376 KB
testcase_06 AC 23 ms
5,792 KB
testcase_07 AC 6 ms
4,376 KB
testcase_08 AC 16 ms
4,404 KB
testcase_09 AC 17 ms
5,152 KB
testcase_10 AC 5 ms
4,376 KB
testcase_11 AC 5 ms
4,380 KB
testcase_12 AC 3 ms
4,376 KB
testcase_13 AC 15 ms
5,900 KB
testcase_14 AC 8 ms
4,380 KB
testcase_15 AC 0 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 1 ms
4,384 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 ms
4,384 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 1 ms
4,384 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 10 ms
4,380 KB
testcase_29 AC 7 ms
4,380 KB
testcase_30 AC 5 ms
4,380 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 summary = 0usize;
    let mut result = 0usize;
    let mut pque = BinaryHeap::new();
    for i in (1..n).rev() {
        if pque.len() < k {
            summary += a[i];
            pque.push(Reverse(a[i]));
            if i % 2 == 1 {
                result = summary;
            }
        } else {
            if i % 2 == 1 {
                result = result.max(summary - pque.peek().unwrap().0 + a[i]);
            }
            pque.push(Reverse(a[i]));
            summary += a[i];
            summary -= pque.pop().unwrap().0;
        }
    }
    println!("{}", result);
}
0