#K40132. Calculate Final Cart Price with Best Discount Coupon

    ID: 26575 Type: Default 1000ms 256MiB

Calculate Final Cart Price with Best Discount Coupon

Calculate Final Cart Price with Best Discount Coupon

You are given a shopping cart with a list of items and a set of discount coupons. Each item is characterized by its price and quantity, while each coupon is defined by a minimum cart value and a discount percentage.

Your task is to compute the final price of the cart after applying the single best discount coupon. A coupon is applicable only if the total cart value \(T\) satisfies \(T \ge X\), where \(X\) is the minimum cart value required by the coupon. The discount offered by a coupon is calculated as follows:

\(\text{discount} = T \times \frac{D}{100}\)

The final price is given by:

\(\text{Final Price} = T - \text{max_discount}\)

where \(\text{max_discount}\) is the maximum discount obtainable from any applicable coupon. If no coupon is applicable, the final price is simply the total cart value.

inputFormat

The input is read from stdin and has the following format:

  1. An integer \(n\) representing the number of items in the cart.
  2. Next, \(n\) lines follow, each containing two integers: \(P\) (price of the item) and \(Q\) (quantity of the item).
  3. An integer \(m\) representing the number of discount coupons.
  4. Then, \(m\) lines follow, each containing two integers: \(X\) (minimum cart value required) and \(D\) (discount percentage).

outputFormat

Output to stdout a single floating point number which is the final price of the cart after applying the best applicable discount coupon. The answer should be accurate up to at least one decimal place.

## sample
3
100 2
200 1
300 3
0
1300.0

</p>