#P3274. [SCOI2011] 植物大战僵尸

[SCOI2011] 植物大战僵尸

Description

Walnut Bowling is a minigame in Plants vs. Zombies. Now Crazy Dave only gave lxhgww some ordinary walnuts and asked lxhgww to throw them like bowling balls to smash the zombies in the yard.

The yard consists of NN lanes, numbered from 11 to NN from top to bottom. Each lane is divided into cells. There are MM zombies in total, each standing in some cell, and you may assume their positions are fixed.

The game has KK rounds. In each round, you can choose one lane and throw a walnut. The thrown walnut first rolls straight from left to right along that lane. After it hits the first zombie, it begins to roll along a 4545-degree diagonal toward the center line of the yard (that is, in the first N/2N/2 lanes it rolls down-right, and in the last N/2N/2 lanes it rolls up-right; it is guaranteed that NN is even). The yard is bounded by walls. When a diagonally moving walnut hits a wall or a zombie, it bounces: up-right becomes down-right, or vice versa. The round ends when the walnut can no longer hit any zombie.

Note: Multiple zombies may stand in the same cell; in that case, each time the walnut only kills one zombie in that cell. To kill as many zombies as possible, at the start of each round lxhgww chooses the lane whose resulting path will kill the maximum number of zombies under the current state. When there is a tie, he chooses the lane with the smallest index.

To evaluate this strategy, lxhgww needs your help to compute the number of zombies that can be killed by this method.

Input Format

The first line contains three integers NN, MM, KK. Then each of the next MM lines contains two integers XiX_i, YiY_i, meaning that the ii-th zombie is at lane YiY_i, column XiX_i (the XiX_i-th cell from the left).

Output Format

Output K+1K+1 lines. The first KK lines each contain two integers Ai,BiA_i, B_i, meaning that in the ii-th round, the walnut is thrown from lane AiA_i and hits BiB_i zombies during its movement. The last line contains a single integer: the total number of zombies hit.

4 2 1
1 2
5 2
2 2
2

Hint

Constraints

For 20%20\% of the testdata, it is guaranteed that: N200N \le 200, M500M \le 500, K200K \le 200, Xi200X_i \le 200.

For 50%50\% of the testdata, it is guaranteed that: N200N \le 200, M2×105M \le 2\times 10^5, K200K \le 200, Xi106X_i \le 10^6.

For 100%100\% of the testdata, it is guaranteed that: N20000N \le 20000, M2×105M \le 2\times 10^5, K105K \le 10^5, Xi106X_i \le 10^6.

For all testdata, it is guaranteed that: 1YiN1 \le Y_i \le N.

Translated by ChatGPT 5