use std::{collections::BinaryHeap, cmp::Reverse}; fn main() { let mut nk = String::new(); std::io::stdin().read_line(&mut nk).ok(); let nk: Vec = 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 = 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); }