Codeforces Global Round 27
E
Monster
Codeforces
2300
原题
← DF →
翻译中…

Man, this Genshin boss is so hard. Good thing they have a top-up of $6$ coins for only $ \$4.99$. I should be careful and spend no more than I need to, lest my mom catches me...

翻译中…

You are fighting a monster with $z$ health using a weapon with $d$ damage. Initially, $d=0$. You can perform the following operations.

翻译中…
  • Increase $d$ — the damage of your weapon by $1$, costing $x$ coins.
  • Attack the monster, dealing $d$ damage and costing $y$ coins.
翻译中…

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.

翻译中…

Input

翻译中…

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.

翻译中…

Output

翻译中…

For each test case, output the minimum number of coins needed to defeat the monster.

翻译中…

Note

翻译中…

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:

翻译中…
  • Increase damage by $1$, costing $2$ coins.
  • Increase damage by $1$, costing $2$ coins.
  • Increase damage by $1$, costing $2$ coins.
  • Attack the monster, dealing $3$ damage, costing $3$ coins.
  • Attack the monster, dealing $3$ damage, costing $3$ 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:

翻译中…
  • Increase damage by $5$, costing $5\cdot x$ = $50$ coins.
  • Attack the monster once, dealing $5$ damage, costing $20$ coins.
  • Increase damage by $2$, costing $2\cdot x$ = $20$ coins.
  • Attack the monster $5$ times, dealing $5\cdot 7 = 35$ damage, costing $5\cdot y$ = $100$ 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.

翻译中…

样例

Input #1
4
2 3 5 5
10 20 40 5
1 60 100 10
60 1 100 10
Output #1
12
190
280
160
InputCopy OutputCopy
题目信息
题号
2035E
时间限制
2 s
内存限制
256 MB
标签
二分
暴力
构造
贪心
模拟
数学
三分

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。