2479: Task processing
Description
Vasya wants to create a computing system to process arbitrary tasks. As a part of the system he needs an algorithm which will choose an order of task execution.
He came up with the following algorithm:
- There is a single execution queue. For task to be completed, it needs to be added to the queue.
- For each task two values are known: li and ti − the number of seconds that it takes to complete the task and the moment of time when this task is added to the execution queue.
- If at some moment of time T the algorithm has to select a task for execution, it picks the one with the minimum value of li-(T-ti)2. In case of a tie, algorithm picks a task with the lowest index. Then for the following li seconds the algorithm will wait for the task to be completed.
In order to test the algorithm Vasya wants you to simulate it.
You are given n tasks. For each task, you know the number of seconds li that it takes to complete the task and the moment of time ti when this task is added to the execution queue.
For each task find out the moment of time when it will be completed.
The first line contains an integer number n (1≤n≤105)− the number of task to process. The next n lines contain two integers each: li,ti (1≤li≤105,0≤ti≤105).
Print n space-separated integers. The i-th integer is the moment of time when the i-th task was completed.
1
10 5
15
3
3 0
4 3
5 2
3 7 12
3
3 0
4 2
5 1
3 12 8
6
3 0
5 1
4 2
5 18
4 19
5 14
3 8 12 24 28 19