#ARC122F. [ARC122F] Domination

[ARC122F] Domination

Score : 12001200 points

Problem Statement

There are NN red stones and MM blue stones on a two-dimensional plane. The ii-th red stone is at coordinates (RXi,RYi)(RX_i,RY_i), and the jj-th blue stone is at (BXj,BYj)(BX_j,BY_j). There may be multiple stones at the same coordinates.

You can choose a blue stone and move it to anywhere you like, any number of times. The cost of moving a blue stone from (x,y)(x, y) to (x,y)(x',y') is xx+yy|x-x'|+|y-y'|.

You want to meet the following condition:

  • For every 1iN1 \leq i \leq N, there are KK or more blue stones to the upper right of the ii-th red stone. More formally, there are KK or more indices 1jM1 \leq j \leq M such that RXiBXjRX_i \leq BX'_j and RYiBYjRY_i \leq BY'_j, where (BXj,BYj)(BX'_j,BY'_j) are the coordinates of the jj-th blue stone after your operations.

Find the minimum total cost needed to achieve your objective.

Constraints

  • 1N1051 \leq N \leq 10^5
  • 1M1051 \leq M \leq 10^5
  • 1Kmin(M,10)1 \leq K \leq \min(M,10)
  • 0RXi,RYi,BXj,BYj1090 \leq RX_i,RY_i,BX_j,BY_j \leq 10^9
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN MM KK

RX1RX_1 RY1RY_1

RX2RX_2 RY2RY_2

\vdots

RXNRX_N RYNRY_N

BX1BX_1 BY1BY_1

BX2BX_2 BY2BY_2

\vdots

BXMBX_M BYMBY_M

Output

Print the answer.

3 2 1
0 0
2 0
0 2
1 0
0 1
2

The optimal moves are as follows.

  • Move the first blue stone to (2,0)(2,0), for the cost of 12+00=1|1-2|+|0-0|=1.
  • Move the second blue stone to (0,2)(0,2), for the cost of 00+12=1|0-0|+|1-2|=1.
3 2 2
0 0
2 0
0 2
1 0
0 1
6

The optimal moves are as follows.

  • Move the first blue stone to (2,2)(2,2), for the cost of 12+02=3|1-2|+|0-2|=3.
  • Move the second blue stone to (2,2)(2,2), for the cost of 02+12=3|0-2|+|1-2|=3.
10 10 3
985971569 9592031
934345597 151698665
212173157 492617927
623299445 288193327
381549360 462770084
681791249 242910920
569404932 353061961
357882677 463919940
110389433 533715995
9639432 700209424
771167518 75925290
439954587 566974581
738467799 122646638
267815107 900808287
886340750 70087431
434010239 822484872
388269208 879859813
393002209 874330449
154134229 924857472
667626345 460737380
1165266772