Given progressive tax bands and each friend's prior income, find the smallest pre-tax gift that leaves the friend with exactly the required after-tax amount.
Medium6Binary searchMathImplementationNo attempts yetTime limit2sMemory limit512 MBGeorge has won the lottery and wants to share the money with his friends. A gift is taxed once it gets large enough, and the tax depends on how much the friend has already earned that year.
Tax is worked out with tax bands. The bands start at zero and follow one another. Each band taxes the part of the income that falls inside it at its own rate. The last band applies to all income above the sum of the sizes of the other bands.
If a friend has already earned e this year and George hands over a pre-tax amount g, that friend's income for the year rises from e to e+g. The tax due is the total tax on income e+g minus the total tax on income e, and the friend keeps g minus that tax.
You are given the number of tax bands, how much each friend has earned, and how much each friend has to keep after tax. Work out how much George gives each friend before tax.
The tax bands are given from the lowest band to the highest.
Print F lines, one per friend, in the order the friends are given.
Each line holds the pre-tax amount George gives that friend, rounded to exactly six decimal places. When several amounts leave the friend with exactly mj, print the smallest one.