#BS0000390. Tặng tiền và tính thuế (Taxing Problem)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Tặng tiền và tính thuế (Taxing Problem)
Taxing Problem
Source: Kattis
Version: Phuoc Hung OJ Extended
Problem Statement
George won the lottery and wishes to share money with his friends. A gift is added to the recipient’s annual income and taxed progressively. There are finite tax bands beginning at zero income. Band has width pounds and tax rate . Bands are consecutive and disjoint; income beyond all finite bands is taxed at rate . For friend , George knows existing gross income and wants the friend to receive exactly additional pounds after tax. Only tax arising from the gift is deducted from the gift. Find the gross gift for every friend. If multiple gifts give the required net amount, choose the smallest.
Input
The first line contains integer . The next lines, in increasing income-boundary order, each contain real numbers , the width and tax rate of band . The next line contains real number , the final tax rate. The next line contains integer , the number of friends. Each of the next lines contains real numbers , existing gross income and desired additional net amount in pounds.
Output
Print lines in input order. Each line contains the smallest gross gift for the corresponding friend. Absolute or relative error at most is accepted.
Subtasks
- Subtask 1 (20 points): ; ; (); ; ; ; ().
- Subtask 2 (30 points): ; ; (); ; ; ; ().
- Subtask 3 (50 points): ; ; (); ; ; ; ().
Examples
Input
1
1000 0
20
3
0 500
999.5 500
1000 500
Output
500
624.875
625
Explanation
The first friend has enough untaxed income space, so receives 500. The second receives 0.5 untaxed and needs 499.5 net at 20% tax, costing 624.375; total 624.875. The third has exhausted the first band, so needs 500/0.8=625.
Input
3
4750.5 0
8000 20
10000 40
60
3
0 10000
10000 5000
15000 5000
Output
11312.375
7416.5
8624.75
Explanation
The first gets 4750.5 untaxed and needs 5249.5 net at 20%, costing 6561.875; total 11312.375. The second gets 2200.4 from 2750.5 at 20%, then 2799.6 net at 40%, costing 4666; total 7416.5. The third gets 4650.3 from 7750.5 at 40%, then 349.7 net at 60%, costing 874.25; total 8624.75.
Input
2
100 0
100 100
50
2
0 100
0 101
Output
100
202
Explanation
The first friend needs only 100 in the untaxed band; the next 100 would be fully taxed, so 100 is the smallest valid gift. The second needs 101; the first 200 yields 100 net, and 2 at the 50% rate adds 1, totaling 202.