Problem H
Taxing Problem

George has won the lottery and, being a nice guy, has decided to spread the wealth around. However, monetary gifts can be taxed once they get over a certain sizeā€”the amount of tax depends on how much his friends have earned that year.

The amount of tax paid depends on tax bands. The bands start at zero. Each one takes a certain cut of income from the range of pre-tax income it covers. The final tax band applies to all income above its lower bound.

George is a savvy fellow and knows the number of tax bands, the amount of money each friend has earned and the amount he wants each friend to walk away with.

How much should George give to each friend before tax?


  • One line containing an integer $B$ ($1 \le B \le 20$): the number of tax bands.

  • $B$ further lines, each containing two real numbers: $s_ i$ ($0 < s_ i \le 10^6$): the size in pounds of the $i^{th}$ tax band, and $p_ i$ ($0 \le p_ i \le 100$): the percentage taxation for that band.

  • One line containing a real number $P$ ($0 \le P \le 99.999$): the percentage tax on all income above other bands.

  • One line containing an integer $F$, ($0 < F \le 20$): the number of friends George wants to pay.

  • $F$ further lines, each containing two real numbers $e_ j$ and $m_ j$ ($0 \le e_ j \le 10^6$, $0 < m_ j \le 10^6$): the amount of money the $j^{th}$ friend has earned, and the amount of money they should receive after tax respectively.

Tax bands will be given in increasing order. All real numbers have at most $6$ decimals after the decimal point.


  • $F$ lines, one for each friend specified in the input and in the same order.

    Each line should contain one real number: the amount of money George will give to his friend, in order to arrive at the correct amount after they have paid tax.

All output must be accurate to an absolute or relative error of at most $10^{-6}$.

Sample Input 1 Sample Output 1
1000 0
0.0 500
999.5 500
1000.0 500
Sample Input 2 Sample Output 2
4750.50 0
8000 20
10000 40
0 10000
10000 5000
15000 5000

Please log in to submit a solution to this problem

Log in