DWITE, January 2012, Problem 5
Comets have recently passed through your region of space, leaving behind a trail of dust. You would like to get a rough idea of the extent of this pollution, by finding the two most distant dust particles. Here, we define distance as the sum of differences between the , , and coordinates. For example, the distance between two particles at and is .
There are comets, and we describe each comet with numbers: , , , and . A comet's position at time is given by . A comet leaves behind a particle of dust at every integer time between and , inclusive.
For example, consider a comet described by , , , and . It leaves behind 5 dust particles, at , , , , and . The first and last points are the most distant pair, with distance .
Pay close attention to the bounds. You may assume that there will be fewer than dust particles, and that all positions will fit within a signed 32-bit integer.
The input will contain 5 test cases. Each will begin with a single integer . lines will follow, each containing integers, in the order described above.
The output will contain 5 lines of output, one integer for each test case: the distance between the most distant pair of dust particles. There will be at least 2 dust particles.
Sample Input
1
1 0 0 0 -2 1 0 0 6 1 5
3
3 1 4 1 5 9 2 6 5 3 58
2 7 1 8 2 8 1 8 2 8 45
1 6 1 8 0 3 3 9 8 8 74
Sample Output
32
66726
Problem Resource: DWITE
Comments