#K55862. Calculate Best Price

    ID: 30070 Type: Default 1000ms 256MiB

Calculate Best Price

Calculate Best Price

In this problem, you are given the original price (p) of an item and a list of discount offers available at various stores. There are three types of discounts:

  1. Fixed Discount: Subtract a fixed amount (d) from (p), resulting in (p - d).
  2. Percentage Discount: Reduce (p) by (r)% to get (p \times \left(1 - \frac{r}{100}\right)).
  3. BOGO Discount: A "Buy One Get One" deal that halves the price, i.e., (\frac{p}{2}).

Your task is to determine the best (lowest) final price achievable by applying exactly one of the discount offers. When performing calculations, truncate any decimal parts by converting the result to an integer.

For example, if (p = 100) with three discounts: a fixed discount of 20, a percentage discount of 25%, and a BOGO discount, the possible final prices are 80, 75, and 50 respectively. The best final price is 50.

Make sure to use the input from STDIN and output the result to STDOUT.

inputFormat

Input is read from STDIN. The first line contains two integers: (n) (the number of stores) and (p) (the original price). The second line contains one integer (m), the number of discount offers. Each of the following (m) lines describes one discount offer in one of the following formats:

  • For a fixed discount: fixed d where (d) is the discount amount.
  • For a percentage discount: percentage r where (r) is the discount percentage.
  • For a BOGO discount: bogo.

Note: The discount types are case sensitive.

outputFormat

Output a single integer to STDOUT representing the best final price after applying the optimal discount.## sample

1 100
1
fixed 20
80

</p>