#P7216. [JOISC 2020] 美味しい美味しいハンバーグ

[JOISC 2020] 美味しい美味しいハンバーグ

Description

There is a 109×10910^9 \times 10^9 metal grid, where (x,y)(x,y) denotes the cell in the xx-th column from left to right and the yy-th row from top to bottom (1x,y1091\leq x,y\leq 10^9). On this grid, there are NN hamburger patties, numbered 1,,N1,\cdots,N. The ii-th patty is placed inside the rectangular region with bottom-left corner (Li,Di)(L_i,D_i) and top-right corner (Ri,Ui)(R_i,U_i). Patties may overlap.

You need to check whether all patties are cooked. You may choose KK cells on the metal grid and insert a bamboo skewer vertically through the center of each chosen cell. For each patty, you can confirm whether it is cooked by inserting a skewer into a cell that the patty occupies. Of course, you may insert multiple skewers into the same cell, or insert skewers into cells with no patty, although that is unnecessary.

Formally, you need to find KK points (x1,y1),,(xk,yk)(x_1,y_1),\cdots,(x_k,y_k) that satisfy the following conditions:

  • For every ii, there exists a jj such that LixjRiL_i\leq x_j\leq R_i and DiyjUiD_i\leq y_j\leq U_i.

  • For every jj, 1xj,yj1091\leq x_j,y_j\leq 10^9.

You need to write a program to output these KK points (xj,yj)(x_j,y_j). The testdata guarantees that a solution exists.

Input Format

The first line contains two integers N,KN,K, as described above.

The next NN lines each contain four integers Li,Di,Ri,UiL_i,D_i,R_i,U_i, describing one hamburger patty.

Output Format

Output KK lines, each containing two integers xjx_j and yjy_j.

If there are multiple solutions, you may output any one.

4 2
2 1 3 3 
1 2 4 3 
6 1 7 4
5 3 7 5
2 2
7 4
3 3
1 1 1 1
1 2 1 2
1 3 1 3
1 1
1 2
1 3

Hint

Explanation of Sample 1

Inserting a bamboo skewer at (2,2)(2,2) can confirm whether the first two patties are cooked, and inserting a bamboo skewer at (7,4)(7,4) can confirm whether the last two patties are cooked.

Another feasible solution is to insert bamboo skewers at (3,3)(3,3) and (6,4)(6,4).

Subtasks

Subtask ID Special Property Score
11 N2000,K=1N\leq 2000,K=1 11
22 N2000,K=2N\leq 2000,K=2
33 N2000,K=3N\leq 2000,K=3 33
44 N2000,K=4N\leq 2000,K=4 66
55 K=1K=1 11
66 K=2K=2 33
77 K=3K=3 66
88 K=4K=4 7979

For 100%100\% of the testdata, 1N2×1051\leq N\leq 2\times 10^5, 1K41\leq K\leq 4, 1LiRi1091\leq L_i\leq R_i\leq 10^9, and 1DiUi1091\leq D_i\leq U_i\leq 10^9. The testdata guarantees that a solution exists.

Translated by ChatGPT 5