#P6290. [eJOI 2017] 粒子

[eJOI 2017] 粒子

Description

Two linear particle accelerators are placed facing each other at a distance of LL. Accelerator AA fires xx particles, and accelerator BB fires yy particles. When these two types of particles meet, they collide and annihilate. Note that an xx particle can overtake another xx particle and nothing happens. The same applies to yy particles.

Under these conditions, starting from time 00, accelerators AA and BB begin to fire NN xx particles and NN yy particles, respectively. Each particle moves at a constant speed. The xx and yy particles are numbered 1,2,,N1,2,\cdots,N.

Note: during time tt, a particle with speed vv travels a distance s=vts = vt.

The launch times of the xx particles from index 11 to NN are: 0=tx1<tx2<tx3<<txN0 = tx_1 < tx_2 < tx_3 < \cdots < tx_N, and their speeds are: vx1,vx2,vx3,,vxNvx_1, vx_2, vx_3, \cdots, vx_N.

Similarly, the launch times of the yy particles are: 0=ty1<ty2<ty3<<tyN0 = ty_1 < ty_2 < ty_3 < \cdots < ty_N, and their speeds are: vy1,vy2,vy3,,vyNvy_1, vy_2, vy_3, \cdots, vy_N.

During the firing process, the following conditions hold:

  • Each particle will collide with exactly one particle of the opposite type (the xx and yy particles are opposite types to each other).
  • When two particles collide, the distance from every other particle to the collision point will be 1\ge 1. This condition is guaranteed to hold for the first KK collisions.

Your task is to write a program to determine the particle pairs in the first KK collisions.

Input Format

The first line contains three positive integers separated by spaces: N,L,KN, L, K.

The next NN lines each contain two integers: txi,vxitx_i, vx_i.

The next NN lines each contain two integers: tyi,vyity_i, vy_i.

Output Format

Output KK lines in total.

Each line contains two positive integers i,ji, j, indicating the ii-th xx particle and the jj-th yy particle.

Line ll means that the ii-th xx particle and the jj-th yy particle are the ll-th pair to collide, i.e. the output order represents the chronological order of collisions.

4 100 2
0 1
2 3
3 2
6 10
0 5
3 10
5 1
7 20
4 2
2 4

Hint

Constraints

For all testdata, it is guaranteed that:

  • 1N5×1041 \le N \le 5\times 10^4.
  • 1L1091 \le L \le 10^9.
  • 1Kmin(102,N)1 \le K \le \min(10^2, N).
  • txi,tyi[0,109]tx_i, ty_i \in [0, 10^9].
  • vxi,vyi(0,109]vx_i, vy_i \in (0, 10^9].

Among them, for 30%30\% of the testdata, 1N1031 \le N \le 10^3.

Notes

The original problem is from: eJOI2017 Problem C Particles

Translation provided by: @_Wallace_

Translated by ChatGPT 5