Headshot
InterviewTime limit2sMemory limit1024 MB
Given n shots, magazine size m, full reload time a, and per-round load time b, find the minimum total time to fire exactly n shots.
Statement
Agent Johnny English has come across his next target, and he has to kill him. To make sure his clumsiness does not get in the way, he decides to fire exactly shots from his pistol. The pistol has a magazine that holds rounds. It starts empty.
Johnny can fully reload the pistol in seconds, or load one round into the magazine in seconds. Each shot takes exactly one second. Find the minimum time Johnny needs to fire exactly shots. He cannot fire an empty pistol, and he cannot load a round into a full magazine.
Input
The first line contains four integers , , , and (). They are the number of shots to fire, the magazine size, the time for a full reload, and the time to load one round.
Output
Print one integer, the minimum time Johnny needs to fire exactly shots.
Hint
In the test from the statement, Johnny fully reloads once, fires twice, loads one more round, and fires it.