TopCoder problem "SquareCovering" used in TCHS SRM 50 (Division I Level Two)



Problem Statement

    

A square covers a point on a plane if this point lies on the border of this square.

You will be given int[]s px and py, with the i-th elements of px and py representing x and y coordinates of a point on a plane. Find the smallest square with its sides parallel to coordinate axes, which can cover all points from the input and return the length of its side. If no such square exists, return -1.

 

Definition

    
Class:SquareCovering
Method:getMinimalSide
Parameters:int[], int[]
Returns:int
Method signature:int getMinimalSide(int[] px, int[] py)
(be sure your method is public)
    
 

Constraints

-px will contain between 2 and 50 elements, inclusive.
-px and py will contain the same number of elements.
-All elements of px and py will be between -1000 and 1000, inclusive.
-All points specified by px and py will be different.
 

Examples

0)
    
{0,1}
{0,1}
Returns: 1
Both points can be covered with a square with vertices (0,0), (1,0), (1, 1) and (0, 1).
1)
    
{0,1,2}
{0,1,2}
Returns: -1
These points can not be covered by a square.
2)
    
{1,-3, 2}
{1, 0, -4}
Returns: 5
3)
    
{-10, 0, 3, -1}
{0, -1, 3, 4}
Returns: -1
These points can be covered by a rectangle, but not by a square.
4)
    
{1,2,3,4,5,6,7,8,9,10}
{1000,1000,1000,1000,1000,1000,1000,1000,1000,1000}
Returns: 9

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=9772

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=13483&pm=9772

Writer:

it4.kp

Testers:

PabloGilberto , Olexiy , ivan_metelsky

Problem categories:

Simple Math