Codeforces Global Round 27 |
---|
Finished |
You are fighting a monster with $$$z$$$ health using a weapon with $$$d$$$ damage. Initially, $$$d=0$$$. You can perform the following operations.
You cannot perform the first operation for more than $$$k$$$ times in a row.
Find the minimum number of coins needed to defeat the monster by dealing at least $$$z$$$ damage.
The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases.
The only line of each test case contains 4 integers $$$x$$$, $$$y$$$, $$$z$$$, and $$$k$$$ ($$$1\leq x, y, z, k\leq 10^8$$$) — the first operation's cost, the second operation's cost, the monster's health, and the limitation on the first operation.
For each test case, output the minimum number of coins needed to defeat the monster.
42 3 5 510 20 40 51 60 100 1060 1 100 10
12 190 280 160
In the first test case, $$$x = 2$$$, $$$y = 3$$$, $$$z = 5$$$, and $$$k = 5$$$. Here's a strategy that achieves the lowest possible cost of $$$12$$$ coins:
You deal a total of $$$3 + 3 = 6$$$ damage, defeating the monster who has $$$5$$$ health. The total number of coins you use is $$$2 + 2 + 2 + 3 + 3 = 12$$$ coins.
In the second test case, $$$x = 10$$$, $$$y = 20$$$, $$$z = 40$$$, and $$$k = 5$$$. Here's a strategy that achieves the lowest possible cost of $$$190$$$ coins:
You deal a total of $$$5 + 35 = 40$$$ damage, defeating the monster who has exactly $$$40$$$ health. The total number of coins you use is $$$50 + 20 + 20 + 100 = 190$$$ coins.
Name |
---|