OptimalTax
TCO05 Sponsor 3 · 2005-08-16 · by Olexiy
Problem Statement
A city has several different tax schemes. In each scheme, the taxpayer pays a percentage of his income plus a fixed base amount every year. Each citizen is free to choose an optimal tax scheme for his income after the end of each year.
You will be given two
Notes
- The return value must be within 1e-9 absolute or relative error of the actual result
Constraints
- fixedBase and percent will contain between 2 and 50 elements, inclusive.
- fixedBase and percent will contain the same number of elements.
- Each element of fixedBase will be between 0 and 10000, inclusive.
- Each element of percent will be between 0 and 100, inclusive.
- index will be between 0 and number of elements in fixedBase - 1, inclusive.
{10, 5, 3}
{0, 10, 20}
0
Returns: 50.0
The first scheme forces a taxpayer to pay 10 units of tax regardless of income. The second scheme leads to the same tax for an income of 50. The first scheme is optimal for any income greater than that.
{0, 1000}
{5, 3}
1
Returns: 50000.0
{0, 1, 2}
{10, 5, 0}
1
Returns: -1.0
May cause precision problems.
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
{10, 9, 8, 7, 6, 5, 4, 3, 2, 1}
8
Returns: -1.0
{6000, 435, 3325, 2345, 0}
{ 0, 45, 33, 13, 100}
3
Returns: 5968.75
Submissions are judged against all 116 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class OptimalTax with a public method double optimalIncome(vector<int> fixedBase, vector<int> percent, int index) · 116 test cases · 2 s / 256 MB per case