#![allow(non_snake_case, unused_imports)] use std::cmp::Reverse; use std::collections::{BinaryHeap, HashMap, HashSet}; use proconio::{input, marker::Usize1, marker::Chars}; use itertools::Itertools; #[allow(unused_macros)] macro_rules! d { ( $( $x:expr ),* $(,)? ) => { eprintln!( concat!( $( stringify!($x), "={:?} " ),* ), $( $x ),* ); }; } #[allow(dead_code)] fn yn(b: bool) -> &'static str { if b { "Yes" } else { "No" } } fn main() { input! { N: usize, K: usize, X: i64, A: [i64; N], } let mut q = BinaryHeap::>::new(); let mut tot = 0; let mut ans = i64::MIN; for (i, &a) in A.iter().enumerate() { q.push(Reverse(a)); tot += a; if q.len() > K { if let Some(Reverse(x)) = q.pop() { tot -= x; } } let score = tot - X * (i+1) as i64; ans = ans.max(score); } println!("{}", ans); }