PCB | 프로그래밍의 벗 PivotOJ
PivotOJ

PCB

시간 제한: 1000ms메모리 제한: 2048MB출처: ICPC Asia Tehran Regional Contest 2024BOJ 33195

문제

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 iith power supply is located at position (0,hi)(0, h_i) and the iith 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 9090-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 \le W, H \le 10^8; 1n1061 \le n \le 10^6).
  • Each of the next nn lines contains an integer hih_i (1hiH1 \le h_i \le H).
  • Each of the next nn lines contains two integers xix_i and yiy_i (1xiW1 \le x_i \le W; 1yiH1 \le y_i \le 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 iith integer describes pip_i, indicating that power supply ii is connected to consumer pip_i.

예제

예제 1

입력
5 5 2
2
4
3 2
5 4
출력
1 2

예제 2

입력
10 10 5
9
6
2
8
1
2 3
5 8
3 8
4 8
1 2
출력
2 4 5 3 1
코드를 제출하려면 로그인하세요.