#include #include #include using namespace std; int main() { int n, k, x = 0; long long tmp = 0; long long sum = 0; cin >> n; cin >> k; cin >> x; vector a(n); for (auto &nx : a) { cin >> nx; }; sum = -9999999999999999; for (int i = 0; i < n; i++) { vector b(i + 1); for (int j = 0; j <= i; j++) { b[j] = a[j]; } sort(b.rbegin(), b.rend()); tmp = 0; for (int j = 0; j < min(k, i + 1); j++) { tmp = tmp + b[j]; } tmp = tmp - x * (i + 1); if (tmp >= sum) { sum = tmp; } } cout << sum; } // N K X // K は調べる数の数 // A1...AN // 30 20 70 10 60 // i = 1 // 30 - 20 *1 // i = 2 // 30+ 20 - 20*2 // i - 3 // 30 + 70(70>20) -20*3...