#include #include using namespace std; using namespace atcoder; using ll = long long; using ull = unsigned long long; using vi = vector; using vvi = vector; using vl = vector; using vvl = vector; using vs = vector; using vpi = vector>; using vpl = vector>; #define rep(i, s, n) for (int i = (s); i < (int)(n); ++i) #define repr(i, s, n) for (int i = (s); i >= (int)(n); --i) #define sz(x) ((int)(x).size()) template bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;} template bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;} auto _ = []{ios::sync_with_stdio(false); cin.tie(nullptr); return 0;}(); const int INFI = 1 << 30; const ll INFL = 1LL << 62; int main() { ll n, k, x; cin >> n >> k >> x; vl a (n); rep(i, 0, n){ cin >> a[i]; } ll mx=-INFL; priority_queue, greater>q; ll sm=0; rep (i, 0, n){ sm+=a[i]; q.push(a[i]); if(sz(q)>k){ sm-=q.top(); q.pop(); } chmax(mx,sm-x*(i+1)) << '\n'; } cout << mx << '\n'; return 0; }