#P14696. [ICPC 2024 Tehran R] PCB

[ICPC 2024 Tehran R] PCB

题目描述

In designing a printed circuit board (PCB), each consumer must be connected to a power supply via conductive wires. The PCB is a rectangle of width WW and height HH. It is represented as a grid of integer coordinates from (0,0)(0,0) to (W+1,H+1)(W+1,H+1).

There are nn power supplies along the left edge of the board and nn consumers each located somewhere inside the board. The ithi^{th} power supply is located at position (0,hi)(0,h_i) and the ithi^{th} consumer is located at position (xi,yi)(x_i,y_i). Each power supply must connect to exactly one consumer and vice versa.

Each wire must run along the grid lines, bending at most once. i.e., each wire is either a straight vertical or horizontal line or makes exactly one 90-degree turn, forming an "L" shape. Wires cannot cross or overlap with each other anywhere along their paths.

Your task is to determine a matching between power supplies and consumers such that the total length of all wires is minimized.

输入格式

The input consists of several lines:

  • The first line contains three integers WW, HH and nn (1W,H1081 \leq W,H \leq 10^8; 1n1061 \leq n \leq 10^6).
  • Each of the next nn lines contains an integer hih_i (1hiH1 \leq h_i \leq H).
  • Each of the next nn lines contains two integers xix_i and yiy_i (1xiW1 \leq x_i \leq W; 1yiH1 \leq y_i \leq H).

It is guaranteed that each point in the board contains at most one power supply or consumer. Moreover, no two consumers ii and jj exist where xi=xjx_i = x_j.

输出格式

If it is not possible to find such a matching under the given constraints, output a single line containing 1-1.

Otherwise, output a single line containing nn space-separated integers. The ithi^{th} integer describes pip_i, indicating that power supply ii is connected to consumer pip_i.

5 5 2
2
4
3 2
5 4
1 2
10 10 5
9
6
2
8
1
2 3
5 8
3 8
4 8
1 2
2 4 5 3 1