結果
問題 |
No.2028 Even Choice
|
ユーザー |
|
提出日時 | 2022-09-07 12:56:38 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 25 ms / 2,000 ms |
コード長 | 1,034 bytes |
コンパイル時間 | 12,293 ms |
コンパイル使用メモリ | 378,544 KB |
実行使用メモリ | 7,296 KB |
最終ジャッジ日時 | 2024-11-22 16:48:32 |
合計ジャッジ時間 | 15,195 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 28 |
コンパイルメッセージ
warning: unused variable: `n` --> src/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
ソースコード
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); }