結果
問題 |
No.2028 Even Choice
|
ユーザー |
|
提出日時 | 2022-09-28 10:53:55 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 27 ms / 2,000 ms |
コード長 | 1,050 bytes |
コンパイル時間 | 15,058 ms |
コンパイル使用メモリ | 378,596 KB |
実行使用メモリ | 7,296 KB |
最終ジャッジ日時 | 2024-12-22 17:26:22 |
合計ジャッジ時間 | 15,906 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 28 |
ソースコード
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 pque = BinaryHeap::new(); let mut result = 0usize; let mut summary = 0usize; for i in (1..n).rev() { if pque.len() < k { pque.push(Reverse(a[i])); summary += a[i]; if i % 2 == 1 { result = summary; } continue; } let val = pque.peek().unwrap().0; if i % 2 == 1 { result = result.max(summary + a[i] - val); } pque.push(Reverse(a[i])); let val = pque.pop().unwrap().0; summary = summary + a[i] - val; } println!("{}", result); }