#K73912. Rent Splitting Problem
Rent Splitting Problem
Rent Splitting Problem
In this problem, you are given the total monthly rent and a list of students along with the number of days each student stayed during the month. Your task is to split the rent proportionally according to the number of days each student stayed. In other words, if a student stayed for (d_i) days and the total number of days for all students is (D), then the rent owed by that student is given by [ \text{rent}_i = \frac{d_i}{D} \times \text{total_rent} ] Make sure to round the result to two decimal places. You must read from standard input and write the result to standard output.
inputFormat
The input is read from standard input and consists of multiple lines:
- The first line contains a floating-point number representing the total rent for the month.
- The second line contains an integer (N), the number of students.
- Each of the next (N) lines contains a student's name (a string without spaces) and an integer representing the number of days the student stayed, separated by a space.
outputFormat
For each student (in the same order as they appear in the input), output a line in the format:
Name: Amount
Where Amount is the calculated rent contribution for the student, rounded to two decimal places.## sample
300.0
3
Alice 10
Bob 20
Charlie 30
Alice: 50.00
Bob: 100.00
Charlie: 150.00
</p>