結果

問題 No.2028 Even Choice
ユーザー koba-e964koba-e964
提出日時 2022-08-05 23:25:02
言語 Rust
(1.77.0)
結果
AC  
実行時間 58 ms / 2,000 ms
コード長 1,439 bytes
コンパイル時間 3,514 ms
コンパイル使用メモリ 151,252 KB
実行使用メモリ 5,148 KB
最終ジャッジ日時 2023-10-14 01:18:01
合計ジャッジ時間 6,017 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 58 ms
4,436 KB
testcase_01 AC 54 ms
4,700 KB
testcase_02 AC 58 ms
4,348 KB
testcase_03 AC 50 ms
5,148 KB
testcase_04 AC 52 ms
4,888 KB
testcase_05 AC 12 ms
4,352 KB
testcase_06 AC 52 ms
4,348 KB
testcase_07 AC 15 ms
4,352 KB
testcase_08 AC 36 ms
4,356 KB
testcase_09 AC 40 ms
4,348 KB
testcase_10 AC 14 ms
4,356 KB
testcase_11 AC 10 ms
4,352 KB
testcase_12 AC 5 ms
4,352 KB
testcase_13 AC 39 ms
4,352 KB
testcase_14 AC 16 ms
4,352 KB
testcase_15 AC 1 ms
4,348 KB
testcase_16 AC 1 ms
4,352 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,348 KB
testcase_19 AC 1 ms
4,348 KB
testcase_20 AC 1 ms
4,348 KB
testcase_21 AC 1 ms
4,348 KB
testcase_22 AC 1 ms
4,348 KB
testcase_23 AC 1 ms
4,372 KB
testcase_24 AC 1 ms
4,348 KB
testcase_25 AC 1 ms
4,352 KB
testcase_26 AC 1 ms
4,352 KB
testcase_27 AC 1 ms
4,352 KB
testcase_28 AC 29 ms
4,348 KB
testcase_29 AC 20 ms
4,352 KB
testcase_30 AC 14 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::cmp::*;
use std::collections::*;
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes.by_ref().map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr,) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error"));
}

fn main() {
    input! {
        n: usize, k: usize,
        a: [i64; n],
    }
    let mut ma = 0;
    let mut tot = 0;
    let mut que = BinaryHeap::new();
    for i in (0..n).rev() {
        if i % 2 == 1 {
            ma = max(ma, tot + a[i]);
        }
        que.push(Reverse(a[i]));
        tot += a[i];
        if que.len() > k - 1 {
            let Reverse(v) = que.pop().unwrap();
            tot -= v;
        }
    }
    println!("{}", ma);
}
0