National Olympiad in Informatics, China, 1998
Day 1, Problem 1 - Personal Income Tax
A country's income tax law regulates for citizens' personal income taxes to be based on their wage and income.
Wage taxation is calculated on a monthly basis. 800 dollars worth of fees is 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 500 dollars||5|
|2||More than 500 dollars, up to 2000 dollars||10|
|3||More than 2000 dollars, up to 5000 dollars||15|
|4||More than 5000 dollars, up to 20000 dollars||20|
|5||More than 20000 dollars, up to 40000 dollars||25|
|6||More than 40000 dollars, up to 60000 dollars||30|
|7||More than 60000 dollars, up to 80000 dollars||35|
|8||More than 80000 dollars, up to 100000 dollars||40|
|9||More than 100000 dollars||45|
Income taxation is calculated independently, and separately each payout instance. For each payout, if the amount does not exceed 4000 dollars, then 800 dollars of fees is taken away to get the base amount. If the amount exceeds 4000 dollars, then 20% 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 20000 dollars||20|
|2||More than 20000 dollars, up to 50000 dollars||30|
|3||More than 50000 dollars||40|
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 3800 dollars. After subtracting 800 dollars of fees, they apply the remaining 3000 dollars to each of the income brackets. Bracket 1 is completely filled with 500 dollars, bracket 2 is completely filled with 1500 dollars, and bracket 3 gets the remaining 1000 dollars. The rates applied to the brackets are respectively 5%, 10%, and 15%. Thus the total wage tax for that month is 500×5% + 1500×10% + 1000×15% = 325 (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.
The first line of inputs contains one integer M (M ≤ 50000), 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
ID represents the ID of the employee being paid (an integer from 1 to M),
Date is the date of the payout in the format
MM is the month (1 ≤ MM ≤ 12),
DD is the day (1 ≤ DD ≤ 31), 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.
The output contains a positive number P, 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.
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 #
Point Value: 7
Time Limit: 1.00s
Memory Limit: 16M
Added: May 01, 2014
C++03, PAS, C, HASK, ASM, RUBY, PYTH2, JAVA, PHP, SCM, CAML, PERL, C#, C++11, PYTH3