Connection Status:
Competition Arena > Taxes
SRM 125 · 2002-12-16 · by leelin
Class Name: Taxes
Return Type: int
Method Name: calcTaxes
Arg Types: (vector<int>, vector<int>, int)
Problem Statement

Problem Statement

Most countries use a system of individual income tax where the tax rate varies based on the amount of income earned. The United States, for example, uses a progressive tax system where higher income families pay more taxes per dollar than lower income families. Regardless of the system used, it is obvious that having a higher income should still leave an individual better off after taxes than having a lower income (otherwise we would have people trying to make less money in some cases). Also, a person with higher income should pay a total amount greater than or equal to a person with lower income. We ensure this by setting income brackets, described below.

Here is an example of a valid tax system:

  • Anyone with income less than or equal to $4500 pays no taxes
  • Anyone with income over $4500 and less than or equal to $20,000 pays 15% tax only on THE PORTION OVER $4500
  • Anyone with income over $20,000 and less than or equal to $55,000 pays 22% tax on the amount over $20,000 in addition to the income tax households earning $20,000 pay.
  • Anyone with income over $55,000 and less than or equal to $120,000 pays 28% tax on the amount over $55,000 in addition to the income tax households earning $55,000 pay.
  • Anyone with income over $120,000 pays 40% tax on the amount over $120,000 in addition to the income tax households earning $120,000 pay.

In this example, if you earn $70,000, you are in the second highest income bracket and you must pay 28% of $15,000 (because $70,000 - $15,000 = $55,000), 22% of $35,000 (because $55,000 - $35,000 = $20,000), and 15% of $15,500 (because $20,000 - $15,500 = $4,500). The income brackets in this example are the 15% bracket, the 22% bracket, the 28% bracket, and the 40% bracket (also notice that income less than $4500 is not taxed).

Write a method that takes as inputs an income level, income, a int[] of tax percentages, brackets, and a int[] of income cutoffs, cutoffs, for the lower bound of each tax bracket. Return the total amount of tax paid at that income level. The above example translated in this format would be:

brackets = {15, 22, 28, 40}
cutoffs = {4500, 20000, 55000, 120000}
income = 70000

Returns: 15000 * (0.28) + 35000 * (0.22) + 15500 * (0.15) = 14225

Notes

  • The elements of brackets might not be increasing (contrary to the tax system in most countries)
  • Any amount made greater than the highest cutoff is taxed at the rate specified by the highest bracket.
  • Any amount made less than or equal to the lowest cutoff is not taxed.

Constraints

  • Elements of brackets must be ints between 0 and 99 inclusive.
  • Elements of cutoffs must be increasing (cutoffs[i] > cutoffs[i-1]).
  • Elements of cutoffs must be ints between 0 and 10000000 inclusive and divisible by 100
  • brackets and cutoffs must contain the same number of elements.
  • Income must be an int between 0 and 10000000 inclusive and divisible by 100.
Examples
0)
{15, 22, 28, 40}
{4500, 20000, 55000, 120000}
70000
Returns: 14225

The explanation for this example is in the problem statement.

1)
{15, 22, 28, 40}
{4500, 20000, 55000, 120000}
170000
Returns: 48225

This household earns $100,000 more than the one from the previous example. The additional taxes consist of $50,000 extra taxed at 28% and $50,000 extra taxed at 40%. $14225 + (0.28) * $50,000 + (0.40) * $50,000 = $48225

2)
{5}
{0}
100000
Returns: 5000

This system represents a country with a flat-rate 5% income tax regardless of income.

3)
{50}
{0}
500
Returns: 250

The tax on $500 at a rate of 50% is $250.

4)
{15, 22, 28, 40}
{4500, 20000, 55000, 120000}
4000
Returns: 0

Because the lowest cutoff is $4500, a household earning $4000 pays nothing.

5)
{50,50,50,50,50}
{0,100,200,300,400}
500
Returns: 250

This test is meant to ensure that the rounding is not done until the very end. Update - Changed now that rounding is no longer an issue.

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

Coding Area

Language: C++17 · define a public class Taxes with a public method int calcTaxes(vector<int> brackets, vector<int> cutoffs, int income) · 34 test cases · 2 s / 256 MB per case

Submitting as anonymous