結果

問題 No.2028 Even Choice
ユーザー phsplsphspls
提出日時 2022-09-07 12:56:38
言語 Rust
(1.77.0)
結果
AC  
実行時間 26 ms / 2,000 ms
コード長 1,034 bytes
コンパイル時間 4,245 ms
コンパイル使用メモリ 136,180 KB
実行使用メモリ 7,400 KB
最終ジャッジ日時 2023-08-14 17:41:39
合計ジャッジ時間 6,395 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
6,420 KB
testcase_01 AC 22 ms
6,660 KB
testcase_02 AC 26 ms
6,132 KB
testcase_03 AC 15 ms
7,400 KB
testcase_04 AC 18 ms
7,124 KB
testcase_05 AC 5 ms
4,376 KB
testcase_06 AC 23 ms
5,752 KB
testcase_07 AC 6 ms
4,376 KB
testcase_08 AC 16 ms
4,380 KB
testcase_09 AC 16 ms
5,140 KB
testcase_10 AC 5 ms
4,380 KB
testcase_11 AC 5 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 14 ms
5,848 KB
testcase_14 AC 7 ms
4,376 KB
testcase_15 AC 0 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 1 ms
4,384 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 0 ms
4,380 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 10 ms
4,376 KB
testcase_29 AC 7 ms
4,380 KB
testcase_30 AC 5 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused variable: `n`
 --> Main.rs:8:9
  |
8 |     let n = nk[0];
  |         ^ help: if this is intentional, prefix it with an underscore: `_n`
  |
  = note: `#[warn(unused_variables)]` on by default

warning: 1 warning emitted

ソースコード

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 mut a: Vec<usize> = a.trim().split_whitespace().skip(1).map(|s| s.parse().unwrap()).collect();

    let mut result = 0usize;
    let mut pque = BinaryHeap::new();
    let mut summary = 0usize;
    for _ in 0..k {
        let val = a.pop().unwrap();
        summary += val;
        pque.push(Reverse(val));
    }
    if a.len() % 2 == 0 {
        result = summary;
    }
    while a.len() > 0 {
        let val = a.pop().unwrap();
        if a.len() % 2 == 0 {
            result = result.max(summary + val - pque.peek().unwrap().0);
        }
        summary += val;
        pque.push(Reverse(val));
        summary -= pque.pop().unwrap().0;
    }
    println!("{}", result);
}
0