0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-12-25 06:51:58 +00:00
Baoshuo Ren 2022-04-02 20:36:48 +08:00
parent c1db271f6b
commit 262d2c01f9
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

48
AtCoder/ABC246/C/C.cpp Normal file
View File

@ -0,0 +1,48 @@
#include <algorithm>
#include <cmath>
#include <iostream>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 2e5 + 5;
int n, k, x, a[N];
long long sum;
int main() {
std::ios::sync_with_stdio(false);
cin >> n >> k >> x;
for (int i = 1; i <= n; i++) {
cin >> a[i];
sum += a[i];
}
std::sort(a + 1, a + 1 + n, std::greater<int>());
for (int i = 1, t; i <= n; i++) {
if (a[i] < x) break;
t = a[i] / x;
a[i] %= x;
if (k > t) {
k -= t;
sum -= t * x;
} else {
sum -= k * x;
cout << sum << endl;
exit(0);
}
}
std::sort(a + 1, a + 1 + n, std::greater<int>());
for (int i = 1; i <= std::min(n, k); i++) {
sum -= a[i];
}
cout << sum << endl;
return 0;
}