跳到主要内容
图灵 OJTURING / ONLINE JUDGE

#F1521. Task processing

    ID: 1527 传统题 2000ms 256MiB 尝试: 0 已通过: 0 难度: (无) 上传者: 标签>待分类整理状态难度待定难度共享题库Codeforces英文题面题目来源题面语言

Task processing

题目描述

K. Task processing
time limit per test
4 seconds
memory limit per test
512 megabytes
input
standard input
output
standard output

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.

Input

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).

Output

Print n space-separated integers. The i-th integer is the moment of time when the i-th task was completed.

Examples
Input
1
10 5
Output
15 
Input
3
3 0
4 3
5 2
Output
3 7 12 
Input
3
3 0
4 2
5 1
Output
3 12 8 
Input
6
3 0
5 1
4 2
5 18
4 19
5 14
Output
3 8 12 24 28 19 

题目来源:fps-www.educg.net-codeforce-1-2833.xml.zip;FPS 共享题包,题包内第 1036 题。保留原作者与原赛事署名。