intmain(){ std::ios::sync_with_stdio(0); int n, m, c, x; while(cin >> n >> m >> c){ sum[0] = 0; for (int i = 1; i <= n; i++){ cin >> x; sum[i] = sum[i - 1] + x; } sort(sum, sum + n + 1); int l = 0, r = n; ll ans = 0; while(m--){ int temp = sum[r] - sum[l] - c; if (temp <= 0) break; l++, r--; ans += ll(temp); } cout << ans << "\n"; }