408412: GYM103115 F chino with ball

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

F. chino with balltime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

There are N small balls with same weight in horizontal smooth plane. And the volume of these balls can be negligible. All the balls are on the same straight line. There are three possibilities for their initial speed $$$v_0$$$ which is -1 m/s, 0 m/s and 1 m/s.

The initial speed of -1 means that the ball moves to the left along a straight line, the initial speed of 0 means that the ball is still at first, and the initial speed of 1 means that the initial speed of the ball moves to the right in a straight line.

A fully elastic collision occurs when two balls collide against each other.

Fully elastic collision formula is $$$\left\{\begin{matrix}v_1=\frac{(m_1-m_2)v_1+2m_2v_2}{\; \; \; \; \; \; \; \; \; \;m_1+m_2\; \; \; \; \; \; \; \; \; \;}\\ \; \\ v_2=\frac{(m_2-m_1)v_2+2m_1v_1}{\; \; \; \; \; \; \; \; \; \;m_1+m_2\; \; \; \; \; \; \; \; \; \;}\end{matrix}\right.$$$

Among them, $$$m_1, m_2$$$ represent the weight of the two objects that collided. $$$v_1, v_2$$$ represent the speed before the collision.

Don't be worried, this question is not a physics question. You only need to know the exchanging speed at which two objects of exactly the same weight when they collide.

Given the positions and speeds of n balls at the beginning, find their positions k seconds later.

Input

There are two integers in the first input line n,k$$$(1 \leq n \leq 10 ^5, 0 \leq k \leq 10^9 )$$$

In next n input lines, each line of two integers $$$p_i,v_i(-10^9 \leq p_i \leq 10^9,v_i \in \{-1,0,1\})$$$ indicating the initial position and speed of the ball.

It is guaranteed in all input data that all the balls are in different positions at the beginning

Output

There are n integers in a row, and the i-th integer represents the position of the i-th ball after k seconds.

ExamplesInput
4 10
-10 1
10 -1
-7 0
5 0
Output
-7 5 0 0
Input
2 1
5 1
6 -1
Output
5 6
Note

In the first case, assuming the positive direction is the right side, the ball 1 and ball 3 collide in the 3rd second, and the ball 1 stays in place after the collision. The number 3 ball continues to move to the right. In the 5th second, the No. 2 ball and the No. 4 ball collided. After the collision, the No. 2 ball stayed in place and the No. 4 ball continued to move to the left. In the 10th second, the ball 3 and ball 4 collided. Since the volume of the ball is negligible, it can be considered that the positions of both balls are at 0 at the moment of collision.

In the second case,The two balls collided after 0.5 seconds and then continued to move for 0.5 seconds.

加入题单

算法标签: