From 47cb41f721c44a3e89cf09218c59a64e0b703994 Mon Sep 17 00:00:00 2001 From: omagdy7 Date: Mon, 31 Jul 2023 17:55:28 +0300 Subject: Solve 3 problems from div3 --- codeforces/YetAnotherPromotion/main.cpp | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) (limited to 'codeforces/YetAnotherPromotion/main.cpp') diff --git a/codeforces/YetAnotherPromotion/main.cpp b/codeforces/YetAnotherPromotion/main.cpp index a772000..641c42d 100755 --- a/codeforces/YetAnotherPromotion/main.cpp +++ b/codeforces/YetAnotherPromotion/main.cpp @@ -116,27 +116,19 @@ template void print(T val, TS... vals) { * DON'T GET STUCK ON ONE APPROACH */ +// 2 * x + x = 10 +// x(m + 1) = 10 + void solve() { ll a, b, n, m; cin >> a >> b >> n >> m; - if (m >= n) { - cout << min(a, b) * n << '\n'; - return; - } ll ans = 0; - if (m < n) { - if ((a * m) / (m + 1) <= b) { - ans += (n * m / (m + 1)) * a; - int x = (n * m / (m + 1)); - n -= x + x / m; - } else { - ans += b * n; - n = 0; - } - } - if (n == 1) { - ans += min(a, b); + ll rem = n; + if (a * m <= b * (m + 1)) { + ans += a * m * (n / (m + 1)); + rem = n % (m + 1); } + ans += rem * min(a, b); cout << ans << '\n'; } -- cgit v1.2.3