use std::{cmp::Reverse, collections::BinaryHeap}; 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 result = 0usize; let mut summary = 0usize; let a = a.into_iter().skip(1).collect::>(); let mut pque = BinaryHeap::new(); for i in (0..a.len()).rev().take(k) { summary += a[i]; pque.push(Reverse(a[i])); } if (a.len()-k) % 2 == 0 { result = summary; } for i in (0..a.len()).rev().skip(k) { let val = (*pque.peek().unwrap()).0; if i % 2 == 0 { result = result.max(summary + a[i] - val); } pque.push(Reverse(a[i])); summary += a[i]; while pque.len() > k { summary -= pque.pop().unwrap().0; } } println!("{}", result); }