National Olympiad in Informatics, China, 1998
A country's income tax law regulates citizens' personal income taxes to be based on their wage and income.
Wage taxation is calculated on a monthly basis. dollars worth of fees are subtracted from one's total monthly wage, and the result is used as the base amount from which their personal income tax is calculated. The tax rate is outlined in the following table:
Bracket | Base Amount Range (Each Month) | Tax Rate (%) |
---|---|---|
1 | No more than dollars | |
2 | More than dollars, up to dollars | |
3 | More than dollars, up to dollars | |
4 | More than dollars, up to dollars | |
5 | More than dollars, up to dollars | |
6 | More than dollars, up to dollars | |
7 | More than dollars, up to dollars | |
8 | More than dollars, up to dollars | |
9 | More than dollars |
Income taxation is calculated independently, and separately for each payout instance. For each payout, if the amount does not exceed dollars, then dollars of fees is taken away to get the base amount. If the amount exceeds dollars, then of that is subtracted to yield the base amount. The base amount is then used to calculate the income tax rate.
Bracket | Base Amount Range (Each Payout) | Tax Rate (%) |
---|---|---|
1 | No more than dollars | |
2 | More than dollars, up to dollars | |
3 | More than dollars |
From the above, one should realize that both wage and income taxes are to be calculated in a compounded fashion. That is, one must start at the first income bracket and pay as much of that given range as possible according to the rate specified in the bracket. If there is money left over (their current amount exceeds the base amount range), then they move down to the next income bracket, where they apply as much of the excess amount as they can. This continues until they have exhausted all of the value.
For example, an individual's wage for one month is dollars. After subtracting dollars of fees, they apply the remaining dollars to each of the income brackets. Bracket 1 is completely filled with dollars, bracket 2 is completely filled with dollars, and bracket 3 gets the remaining dollars. The rates applied to the brackets are respectively , , and . Thus the total wage tax for that month is (dollars). The calculating process is outlined in the figure given on the left.
You must write a program to help a company keep track of the taxes they have to pay for one year, given the information of all of their payouts (the type of payout, time of payout, and the amount paid). Your program must find the sum of both the wage tax and income tax for all of their employees.
Input Specification
The first line of inputs contains one integer , the number of employees in the company. The remaining lines each describe the information for one payout instance. There are two possible formats:
- Wage tax payout:
PAY ID Date Amount
- Income tax payout:
INCOME ID Date Amount
Here, ID
represents the ID of the employee being paid (an integer from
1 to ), Date
is the date of the payout in the format MM/DD
where
MM
is the month MM
, DD
is the day DD
,
and Amount
is the amount paid in dollars (assume that each
amount is a positive integer no larger than 1 million).
A line with the character #
denotes the end of input. Adjacent
values in the input will be separated by one or more spaces.
Output Specification
The output contains a positive number , the total amount of tax (wage and income) that the company must pay on behalf of all of its employees for that year in dollars. This value must be rounded and displayed to 2 decimal places.
Sample Input
2
PAY 1 2/23 3800
INCOME 2 4/8 4010
INCOME 2 4/18 800
PAY 1 8/14 6700
PAY 1 8/10 1200
PAY 2 12/10 20000
#
Sample Output
5476.60
Problem translated to English by .
Comments