Bananas on Sale
Limits: 2 sec., 512 MiB
Zenyk has \(x\) hryvnias and wants to buy as many bananas as possible. A banana in the store costs \(a\) hryvnias, but there is a special offer: the first \(k\) bananas Zenyk buys cost \(a\) hryvnias each, and every banana after them costs \(b\) hryvnias.
Help Zenyk find out how many bananas he can buy.
Input
The only line contains four integers \(x\), \(a\), \(b\) and \(k\) – the amount of money Zenyk has, the regular price of a banana, the price of a banana after the discount, and the number of bananas that have to be bought at the regular price, respectively.
Output
Print one integer – the largest number of bananas Zenyk can buy.
Constraints
\(0 \le x \le 10^9\),
\(1 \le b < a \le 10^9\),
\(1 \le k \le 10^9\).
Samples
| Input (stdin) | Output (stdout) |
|---|---|
| 30 10 4 2 | 4 |
| Input (stdin) | Output (stdout) |
|---|---|
| 19 10 4 2 | 1 |
Notes
In the first example, the first two bananas cost 20 hryvnias, and the next two cost 8 hryvnias. Zenyk spends 28 hryvnias. A fifth banana would cost 4 more hryvnias, and he does not have enough money left for it.
In the second example, Zenyk has enough money for only one banana. To buy bananas at the discounted price, he would first have to buy two bananas at 10 hryvnias each.
Submit a solution
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|