#P5086. 坐标

坐标

Background

Solution write-up: https://blog.csdn.net/kkkksc03/article/details/84928342.

Xiaoben knows that Minecraft coordinates have three parameters: XX, YY, and ZZ. But in Xiaoben’s eyes, there is a fourth parameter QQ, which represents how much he likes this location. For example, some places are Xiaoben’s home, so QQ will be large; some places are dangerous mines, so QQ will be small.

Problem Description

There are NN coordinates. For the ii-th coordinate with parameters {Xi,Yi,Zi,Qi}\{X _ i, Y _ i, Z _ i, Q _ i\} and the jj-th coordinate with parameters {Xj,Yj,Zj,Qj}\{X _ j, Y _ j, Z _ j, Q _ j\}, if $X _ i - X _ j = Y _ i - Y _ j = Z _ i - Z _ j = Q _ i - Q _ j$, then these coordinates are called beautiful coordinates.

Given NN coordinates, Xiaoben wants to know the minimum value of j−ij - i and the maximum value of i+ji + j among all beautiful coordinate pairs. Can you help him?

Input Format

The input has n+1n + 1 lines. The first line contains an integer nn. Then follow nn lines, each containing four integers XX, YY, ZZ, and QQ.

Output Format

Output one line containing the minimum value of j−ij - i and the maximum value of i+ji + j, separated by a space. The testdata guarantees that a solution exists.

7
1 2 3 4
2 3 4 5
1 4 3 3
5 2 3 5
2 4 5 6
1 4 3 3
2 5 4 4
1 13
10
1 4 3 2
4 4 4 4
2 3 4 5
1 1 1 1
1 2 3 1
3 4 2 1
2 4 5 2
8 9 7 6
0 0 0 0
1 2 3 4
2 14

Hint

Explanation for Sample 1

(1,2,3,4)(1, 2, 3, 4) and (2,3,4,5)(2, 3, 4, 5), or (1,4,3,3)(1, 4, 3, 3) and (2,5,4,4)(2, 5, 4, 4), achieve the minimum value.

For (1,4,3,3)(1, 4, 3, 3) and (2,5,4,4)(2, 5, 4, 4), 6+7=136 + 7 = 13 is the maximum value.

Constraints

For 30%30\% of the data, n≤103n \le 10 ^ 3.

For 100%100\% of the data, 1≤n≤5×1051 \le n \le 5 \times 10 ^ 5, and XX, YY, ZZ, QQ are all within the int range.

Translated by ChatGPT 5