You have a non-negative integer amount describing the total money available for distribution. Money is measured in indivisible integer units, such as cents.
There are also n employees, each described by:
name: a distinct employee namelimit: the greatest amount that employee may receiveAssign the money according to these requirements:
limit.amount exceeds the combined limits, assign every employee their full limit and leave the surplus undistributed.Report the amount ultimately assigned to every employee.
amount n
name_1 limit_1
name_2 limit_2
...
name_n limit_n
List the employees in the order they appeared in the input, together with their assigned amounts:
name_1 amount_received_1
name_2 amount_received_2
...
name_n amount_received_n
0 <= amount <= 10^181 <= n <= 2 * 10^50 <= limit_i <= 10^18name_i is non-empty, unique, and contains no whitespaceInput:
100 3
Alice 100
Bob 100
Charlie 100
Output:
Alice 34
Bob 33
Charlie 33
Explanation: Since 100 cannot be divided evenly among three employees, Alice receives the one-unit remainder because she is first in the input.
Input:
150 3
Alice 40
Bob 100
Charlie 100
Output:
Alice 40
Bob 55
Charlie 55
Explanation: Alice is capped at 40, leaving 110 units to divide equally between Bob and Charlie.