SalaryCalculator
SRM 325 · 2006-11-02 · by Andrew_Lazarev
Problem Statement
At a certain company, a worker is paid an hourly rate of P1 dollars for the first 200 hours he works each month. He is paid an hourly rate of P2 dollars for the remaining hours. Return the minimum number of hours he must work this month to earn salary dollars.
Notes
- Your return value must have an absolute or relative error less than 1e-9.
Constraints
- P1 will be between 1 and 100, inclusive.
- P2 will be between 1 and 100, inclusive.
- salary will be between 1 and 1,000,000, inclusive.
10 15 1000 Returns: 100.0
The worker is paid 10 dollars per hour for the first 200 hours, and 15 dollars per hour for any hours beyond that. To earn 1000 dollars, he only needs to work 100 hours at 10 dollars per hour.
10 15 3000 Returns: 266.6666666666667
The worker is paid 10 dollars per hour for the first 200 hours for a total of 2000 dollars. To earn the extra 1000 dollars, he must work approximately 66.67 hours at 15 dollars per hour.
100 1 1000000 Returns: 980200.0
The company does not like to pay for overtime work.
17 23 973546 Returns: 42380.260869565216
1 1 1 Returns: 1.0
Submissions are judged against all 91 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class SalaryCalculator with a public method double calcHours(int P1, int P2, int salary) · 91 test cases · 2 s / 256 MB per case