use std::{cmp::Reverse, collections::BinaryHeap}; use proconio::input; fn main() { input! { n: usize, k: usize, x: i64, a: [i64; n], } let mut ans = i64::MIN; let mut sum = 0; let mut heap = BinaryHeap::new(); for &a in &a { let b = a - x; sum += b; heap.push(Reverse(a)); if heap.len() > k { sum -= heap.pop().unwrap().0; } ans = ans.max(sum); } println!("{ans}"); }