#C11488. Calculate Fare for Trips

    ID: 40809 Type: Default 1000ms 256MiB

Calculate Fare for Trips

Calculate Fare for Trips

You are given information about several trips. For each trip, you are provided with six integers:

  • \(B\): the passenger threshold
  • \(K\): a constant multiplier
  • \(C\): a constant added in one case
  • \(D\): a constant used in the other case
  • \(P\): the number of passengers
  • \(distance\): the distance traveled in kilometers

The fare is calculated based on the following rule:

If \(P \leq B\), then the fare per kilometer is computed as:

[ fare_per_km = K \times P + C ]

Otherwise, if \(P > B\), the fare per kilometer is:

[ fare_per_km = D + \frac{K \times P}{2} ]

The total fare for that trip is then given by:

[ total_fare = fare_per_km \times distance ]

Your task is to compute the total fare for each trip.

inputFormat

The first line of the input contains an integer \(T\) denoting the number of trips. Each of the following \(T\) lines contains 6 space-separated integers: \(B\), \(K\), \(C\), \(D\), \(P\), and \(distance\).

outputFormat

Print a single line containing \(T\) space-separated integers, where each integer represents the total fare for the corresponding trip.

## sample
1
10 5 20 30 12 15
900