#B4113. Ticket Fare Calculation

    ID: 11770 Type: Default 1000ms 256MiB

Ticket Fare Calculation

Ticket Fare Calculation

Bitaro is riding the JOI Train. The fare is calculated as follows:

For the first $P$ kilometers, the cost is $A$ yen per kilometer. For every kilometer beyond the first $P$ kilometers, the cost is $B$ yen per kilometer.

If Bitaro travels a total of $Q$ kilometers, the ticket fare is:

\[ \text{fare} = \begin{cases} Q \times A, & \text{if } Q \le P,\\ P \times A + (Q - P) \times B, & \text{if } Q > P. \end{cases} \]

Calculate the total ticket price.

inputFormat

The input consists of a single line containing four space-separated integers: P Q A B, where:

  • $P$ is the cutoff distance (in kilometers) for the lower rate,
  • $Q$ is the total distance traveled (in kilometers),
  • $A$ is the cost (in yen) per kilometer for the first $P$ kilometers,
  • $B$ is the cost (in yen) per kilometer after $P$ kilometers.

outputFormat

Print a single integer representing the total ticket fare in yen.

sample

10 5 20 30
100