Given firing times and speeds of N particles from each of two facing accelerators, report the first K collisions between opposite kinds in chronological order.
Hard8SortingTwo pointersSimulationImplementationNo attempts yetTime limit2sMemory limit512 MBTwo linear particle accelerators A and B are placed a distance L apart, facing each other. A fires x-particles toward B, and B fires y-particles toward A. When an x-particle and a y-particle flying against each other meet, they collide and annihilate. Particles of the same kind do not affect each other. An x-particle can overtake another x-particle and a y-particle can overtake another y-particle, and nothing happens to either particle when it does.
At time 0 the two accelerators start firing, N x-particles and N y-particles in total. Each particle moves at its own constant speed. The particles are numbered from 1 to N in the order they are fired, separately for the x-particles and the y-particles.
A particle with speed v travels the distance s=vt in time t. The firing moments of the x-particles are 0=tx1<tx2<⋯<txN and their speeds are vx1,vx2,…,vxN. The firing moments of the y-particles are 0=ty1<ty2<⋯<tyN and their speeds are vy1,vy2,…,vyN. The firing satisfies the following two conditions.
Write a program that determines the first K collisions between particles of the two kinds.
The first line contains three integers N, L, and K separated by spaces.
Each of the next N lines contains the firing moment txi and the speed vxi of an x-particle, separated by a space. The i-th of these lines describes x-particle i.
Each of the last N lines contains the firing moment tyi and the speed vyi of y-particle i in the same format.
Print K lines. Each line contains two integers separated by a space: the number of the x-particle and the number of the y-particle of one collision. Print the collisions in the order they happen, from the first one to the K-th.