Connection Status:
Competition Arena > TaxTable
SRM 267 · 2005-10-05 · by dgoodman · Math
Class Name: TaxTable
Return Type: int
Method Name: income
Arg Types: (int)
Problem Statement

Problem Statement

For those who file jointly and have a taxable income of at least $100,000 the tax for 2004 is calculated from the following table. To calculate your tax, you find the appropriate bracket for your taxable income, multiply your taxable income by the multiplier, and then subtract the subtraction value.


    At_least   Less_than    Multiplier       Subtraction
    100,000     117,250        25%             6,525.00

    117,250     178,650        28%            10,042.50

    178,650     319,100        33%            18,975.00

    319,100        -           35%            25,357.00

When I find out how much tax someone had to pay, I want to be able to figure out what their taxable income was. Create a class TaxTable that contains a method income that is given the taxAmount and calculates the taxable income whose tax is closest to taxAmount. This result is returned, rounded to the nearest dollar (.5 rounds up). If the taxAmount is too low to have come from the table, return -1.

Constraints

  • taxAmount will be between 0 and 1,000,000, inclusive.
  • All values within 1e-6 of the taxable income corresponding to taxAmount will round to the same integer.
Examples
0)
47025
Returns: 200000

The tax on $200,000 is 33% * 200,000 - 18975 which is 47025.

1)
1000
Returns: -1

Anybody who has taxable income of at least $100,000 has a tax that is greater than $1000

2)
47026
Returns: 200003

The tax on $200,000 is exactly $47,025. For each dollar above that we must pay 33 cents additional tax. So the income that results in a tax of exactly $47,026 is $200,003.0303030303.... which rounds to $200,003. Note that a return of 200002 would be incorrect, even though the tax on that amount would be 47025.66 which is close to 47026.

3)
19001
Returns: 102104
4)
19000
Returns: 102100

Submissions are judged against all 80 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class TaxTable with a public method int income(int taxAmount) · 80 test cases · 2 s / 256 MB per case

Submitting as anonymous