Bank
InterviewTime limit2sMemory limit512 MB
Given n dwarves with arrival times, employee service times, and accountant times, simulate a shared employee queue of m servers and a single accountant to find each dwarf's departure time.
- Level
Medium6 of 10
- Topics
- Simulation, Heap, Greedy, Sorting
- Solved
- No attempts yet
Problem
In a distant world, a new bank has opened in the glorious city of Erbovle. The bank has employees who serve clients and one chief accountant.
Dwarves come to the bank to take care of their business. The -th dwarf arrives at the bank minutes after it opens. First he must spend minutes with one of the employees, and then another minutes in the chief accountant's office.
Of course, several dwarves cannot be with the same employee or in the chief accountant's office at the same time, so queues form at the employees and at the chief accountant.
The queue for the employees is shared, and a dwarf from the queue goes to the first employee who becomes free. If two dwarves arrive at the bank at the same time, the one with the smaller index joins the employees' queue first. If a dwarf starts being served by an employee at time , he finishes at time , and at that time another dwarf may start being served by the same employee. A dwarf who arrives at the bank at time may start being served by an employee at any time from onward.
After finishing his business with an employee, the dwarf joins the queue for the chief accountant. Similarly, if two dwarves join this queue at the same time, the one with the smaller index goes first; when one dwarf's service ends, the next dwarf's service may start immediately; and a dwarf may go to the chief accountant from the moment he finishes being served by an employee.
Today dwarves are going to come to the bank. For each one, the time he enters the bank, how long he wants to spend at a window, and how long he wants to spend with the accountant are known. Report the time each dwarf leaves the bank.
Input
The first line contains two integers and (, ), the number of dwarves and employees, respectively. The next lines contain three integers each: , , and (), the arrival time of the -th dwarf, the number of minutes the -th dwarf must spend with a bank employee, and the number of minutes he must spend in the chief accountant's office. The dwarves are given in order of arrival at the bank, that is, for every pair we have .
Output
Print integers; the -th number must be the number of minutes after opening when the -th dwarf leaves the bank.