diff options
Diffstat (limited to 'codeforces/YetAnotherPromotion/main.cpp')
| -rwxr-xr-x | codeforces/YetAnotherPromotion/main.cpp | 24 |
1 files changed, 8 insertions, 16 deletions
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 <typename T, typename... TS> 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'; } |
