結果

問題 No.2028 Even Choice
ユーザー phsplsphspls
提出日時 2022-09-01 23:36:56
言語 Rust
(1.77.0)
結果
AC  
実行時間 27 ms / 2,000 ms
コード長 992 bytes
コンパイル時間 784 ms
コンパイル使用メモリ 165,408 KB
実行使用メモリ 7,296 KB
最終ジャッジ日時 2024-04-26 23:33:04
合計ジャッジ時間 3,120 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
6,816 KB
testcase_01 AC 24 ms
6,940 KB
testcase_02 AC 27 ms
6,940 KB
testcase_03 AC 16 ms
7,296 KB
testcase_04 AC 20 ms
7,040 KB
testcase_05 AC 5 ms
6,944 KB
testcase_06 AC 24 ms
6,940 KB
testcase_07 AC 7 ms
6,948 KB
testcase_08 AC 16 ms
6,944 KB
testcase_09 AC 17 ms
6,944 KB
testcase_10 AC 6 ms
6,944 KB
testcase_11 AC 5 ms
6,944 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 15 ms
6,940 KB
testcase_14 AC 7 ms
6,940 KB
testcase_15 AC 1 ms
6,944 KB
testcase_16 AC 1 ms
6,944 KB
testcase_17 AC 1 ms
6,944 KB
testcase_18 AC 1 ms
6,944 KB
testcase_19 AC 1 ms
6,944 KB
testcase_20 AC 1 ms
6,944 KB
testcase_21 AC 1 ms
6,940 KB
testcase_22 AC 1 ms
6,940 KB
testcase_23 AC 0 ms
6,940 KB
testcase_24 AC 1 ms
6,944 KB
testcase_25 AC 0 ms
6,944 KB
testcase_26 AC 1 ms
6,944 KB
testcase_27 AC 1 ms
6,940 KB
testcase_28 AC 10 ms
6,940 KB
testcase_29 AC 7 ms
6,944 KB
testcase_30 AC 5 ms
6,940 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()).skip(1).collect();

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