import std; void main () { int N, K, X; readln.read(N, K, X); auto A = readln.split.to!(int[]); auto rem = BinaryHeap!(int[], (a, b) => a < b)([]); auto take = BinaryHeap!(int[], (a, b) => b < a)([]); long ans = -long.max; long cur = 0; foreach (i; 0 .. N) { rem.insert(A[i]); if (i + 1 <= K) { take.insert(rem.front()); cur += rem.front(); rem.removeFront(); } while (!rem.empty() && take.front() < rem.front()) { cur -= take.front(); take.removeFront(); take.insert(rem.front()); cur += rem.front(); rem.removeFront(); } cur -= X; ans = max(ans, cur); } writeln(ans); } void read (T...) (string S, ref T args) { import std.conv : to; import std.array : split; auto buf = S.split; foreach (i, ref arg; args) { arg = buf[i].to!(typeof(arg)); } }