The Hunters' Guild collects a tiered royalty on the bounty gold its hunters earn each season. The royalty schedule is given as m tiers; tier i is described by a cap cap_i and a rate rate_i (a percentage), listed in strictly increasing order of cap. The final tier's cap is guaranteed to be at least as large as any bounty amount you are asked about. The royalty is charged tier by tier, in order:
Given the tier schedule and a hunter's total bounty gold for the season, compute the total royalty owed.
Line 1: an integer m, the number of tiers. Next m lines: two integers cap_i and rate_i, the cap and royalty percentage of tier i, given in strictly increasing order of cap. Last line: an integer bounty, the hunter's total bounty gold for the season.
Print a single number: the total royalty owed, printed with exactly 5 digits after the decimal point. An answer within 1e-5 (absolute or relative) of the exact value is accepted.
1 <= m <= 500 1 <= cap_i <= 10^9, strictly increasing across tiers 0 <= rate_i <= 100 0 <= bounty <= cap_{m-1} (the cap of the last tier)
Example 1
Input
3 3 50 7 10 12 25 10
Expected
2.65000
Explanation
Tiers: [3,50%],[7,10%],[12,25%], bounty=10. Tier 0 taxes the first 3 gold at 50% = 1.5. Tier 1 taxes the next 7-3=4 gold at 10% = 0.4. Tier 2 would tax gold from 7 up to 12, but the bounty only reaches 10, so it taxes 10-7=3 gold at 25% = 0.75. Total = 1.5+0.4+0.75 = 2.65000.
Example 2
Input
1 5 20 5
Expected
1.00000
Explanation
A single tier caps at 5 gold at 20%. The bounty is exactly 5, so all 5 gold falls in this tier: 5*0.20 = 1.00000.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →