atcoder#ARC129B. [ARC129B] Range Point Distance

[ARC129B] Range Point Distance

Score : 400400 points

Problem Statement

For integers ll, rr, and xx (lrl \leq r), let us define dist(l,r,x)dist(l,r,x) as follows.

  • If x:x: dist(l,r,x)=l-x$
  • If lxrl \leq x \leq r: dist(l,r,x)=0dist(l,r,x)=0
  • If r:r: dist(l,r,x)=x-r$

You are given NN pairs of integers, the ii-th of which is (Li,Ri)(L_i,R_i). For each k=1,2,,Nk=1,2,\cdots,N, solve the following problem.

  • Let us choose an integer xx freely and compute $\max(dist(L_1,R_1,x),dist(L_2,R_2,x),\cdots,dist(L_k,R_k,x))$. Find the minimum possible value of this.

Constraints

  • 1N2×1051 \leq N \leq 2 \times 10^5
  • 1LiRi1091 \leq L_i \leq R_i \leq 10^9
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN

L1L_1 R1R_1

L2L_2 R2R_2

\vdots

LNL_N RNR_N

Output

Print the answers for k=1,2,,Nk=1,2,\cdots,N in this order.

3
1 3
2 4
5 6
0
0
1
  • For k=1k=1, an optimal choice is x=1x=1.
  • For k=2k=2, an optimal choice is x=3x=3.
  • For k=3k=3, an optimal choice is x=4x=4.
10
64 96
30 78
52 61
18 28
9 34
42 86
11 49
1 79
13 59
70 95
0
0
2
18
18
18
18
18
18
21