#K52707. Calculate Final Amounts After Discounts

    ID: 29369 Type: Default 1000ms 256MiB

Calculate Final Amounts After Discounts

Calculate Final Amounts After Discounts

You are given a set of discount brackets and a list of customer purchase amounts. Each discount bracket is defined by a minimum purchase threshold and a discount value. For each customer's purchase, your task is to apply the discount from the bracket with the highest minimum purchase threshold that does not exceed the purchase amount. If no discount bracket applies, the customer pays the full amount.

Formally, given M discount brackets and K customer purchase amounts, for each purchase P, find the discount bracket (with minimum purchase T and discount D) such that P \ge T and T is maximized. Then, output the final amount P - D. If no such discount exists, output P unchanged.

Note: All formulas are represented in LaTeX. For example, if a customer purchase is \(P\) and the applicable discount is \(D\), the final amount is \(P - D\).

inputFormat

The first line contains two space-separated integers M and K, where:

  • M is the number of discount brackets.
  • K is the number of customers.

The next M lines each contain two space-separated integers representing a discount bracket. Each bracket is given as:

  • T: the minimum purchase threshold.
  • D: the discount amount.

The following K lines each contain a single integer representing a customer's purchase amount.

outputFormat

Output exactly K lines. Each line should contain a single integer representing the final amount the customer must pay after applying the discount (if any). If no discount applies, the output is the original purchase amount.

## sample
3 4
5000 500
10000 1200
20000 3000
8000
15000
22000
4000
7500

13800 19000 4000

</p>