結果

問題 No.2028 Even Choice
ユーザー koba-e964koba-e964
提出日時 2022-08-05 21:41:07
言語 Rust
(1.77.0)
結果
AC  
実行時間 59 ms / 2,000 ms
コード長 1,798 bytes
コンパイル時間 4,068 ms
コンパイル使用メモリ 153,868 KB
実行使用メモリ 5,160 KB
最終ジャッジ日時 2023-10-13 22:17:31
合計ジャッジ時間 6,213 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 58 ms
4,440 KB
testcase_01 AC 55 ms
4,636 KB
testcase_02 AC 59 ms
4,352 KB
testcase_03 AC 50 ms
5,160 KB
testcase_04 AC 53 ms
4,944 KB
testcase_05 AC 12 ms
4,348 KB
testcase_06 AC 52 ms
4,348 KB
testcase_07 AC 14 ms
4,352 KB
testcase_08 AC 36 ms
4,352 KB
testcase_09 AC 40 ms
4,348 KB
testcase_10 AC 14 ms
4,348 KB
testcase_11 AC 10 ms
4,348 KB
testcase_12 AC 5 ms
4,348 KB
testcase_13 AC 39 ms
4,348 KB
testcase_14 AC 16 ms
4,348 KB
testcase_15 AC 1 ms
4,348 KB
testcase_16 AC 1 ms
4,348 KB
testcase_17 AC 1 ms
4,348 KB
testcase_18 AC 1 ms
4,352 KB
testcase_19 AC 1 ms
4,352 KB
testcase_20 AC 1 ms
4,356 KB
testcase_21 AC 1 ms
4,348 KB
testcase_22 AC 1 ms
4,352 KB
testcase_23 AC 1 ms
4,348 KB
testcase_24 AC 1 ms
4,352 KB
testcase_25 AC 1 ms
4,352 KB
testcase_26 AC 1 ms
4,348 KB
testcase_27 AC 1 ms
4,352 KB
testcase_28 AC 30 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),* )) => { ($(read_value!($next, $t)),*) };
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, usize1) => (read_value!($next, usize) - 1);
    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        read_value!($next, [$t; len])
    }};
    ($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