#P1367. 蚂蚁

蚂蚁

Description

There are many ants on an infinitely long stick. Each ant has an initial position and an initial direction (no two ants share the same initial position). The ants move forward in their current direction at a speed of 1 unit per second. When two ants meet, they turn around (the turning time is negligible). Given the initial position and initial direction of each ant, please compute their positions and directions after tt seconds.

Input Format

The first line contains two space-separated integers n,tn, t (the number of ants nn and the time tt).

Lines 22 to n+1n+1 each contain two integers. Line i+1i+1 gives the initial position aia_i and initial direction bib_i of the ii-th ant (bi=1b_i = 1 means facing right, bi=1b_i = -1 means facing left).

Output Format

Output nn lines, each containing two integers. The ii-th line represents the position and direction of the ii-th ant after tt seconds (1-1 means facing left, 11 means facing right, 00 means currently turning).

4 1
1 1
5 1
3 -1 
10 1

2 0
6 1
2 0
11 1

Hint

Constraints and Conventions

  • For 40%40\% of the testdata, 1n1001 \le n \le 100.
  • For 80%80\% of the testdata, 1n1041 \le n \le 10^4, 0t10000 \le t \le 1000.
  • For 100%100\% of the testdata, n105n \le 10^5, 0t1050 \le t \le 10^5, ai106|a_i| \le 10^6.

Translated by ChatGPT 5