From 262d2c01f98586640fee167db934a699d52817fc Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Sat, 2 Apr 2022 20:36:48 +0800 Subject: [PATCH] C - Coupon https://atcoder.jp/contests/abc246/submissions/30648451 --- AtCoder/ABC246/C/C.cpp | 48 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 AtCoder/ABC246/C/C.cpp diff --git a/AtCoder/ABC246/C/C.cpp b/AtCoder/ABC246/C/C.cpp new file mode 100644 index 00000000..1c263e02 --- /dev/null +++ b/AtCoder/ABC246/C/C.cpp @@ -0,0 +1,48 @@ +#include +#include +#include + +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()); + 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()); + for (int i = 1; i <= std::min(n, k); i++) { + sum -= a[i]; + } + + cout << sum << endl; + + return 0; +}