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 mut a: Vec = 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); }