Dome of the Circus

Time limit1sMemory limit128 MB

Summary
Given 3D points, find the minimum-volume cone with apex on the z-axis and base on the ground plane that contains all points, then output its height and radius.
Level

Hard8 of 10

Topics
Binary search, Geometry, Math
Solved
No attempts yet

Problem

A travelling circus needs to design the dome for its aerial performances. Various rigs, supports, and anchors are installed in the air above the stage, and the dome must rise above the centre of the stage in the shape of a cone and cover all of them. Because the space under the dome must be air-conditioned, the dome should enclose the smallest possible volume.

You are given nn points in space. The point (xi,yi,zi)(x_i, y_i, z_i) is the position of the ii-th object that must be covered, for 1≤i≤n1 \le i \le n. The ground is the plane z=0z = 0, with positive zz pointing up, and the centre of the stage is the origin (0,0,0)(0, 0, 0).

The tip of the dome is a point (0,0,h)(0, 0, h) with h>0h > 0. The dome is a cone whose base is the circle of radius rr centred at (0,0,0)(0, 0, 0) on the ground. Every given point must lie inside or on the surface of the cone. Among all such cones, find the one with the smallest volume.

Input

The first line contains a single integer nn (1≤n≤10 0001 \le n \le 10\,000) — the number of points to cover. Each of the next nn lines contains three floating-point numbers xix_i, yiy_i, and ziz_i — the coordinates of the ii-th point. Every coordinate has absolute value at most 10001000 and at most two digits after the decimal point. Every ziz_i is positive, and at least one point has a non-zero xix_i or yiy_i.

Output

Print two numbers hh and rr separated by a single space: the height and the base radius of the minimum-volume dome. Print each value rounded to exactly three digits after the decimal point (for example, 3.000). The optimal dome is unique, so both values are uniquely determined.

Examples5

  1. Example 1

    Input
    1
    1.00 0.00 1.00
    
    Expected output
    3.000 1.500
    
  2. Example 2

    Input
    2
    1.00 0.00 1.00
    0.00 1.50 0.50
    
    Expected output
    2.000 2.000
    
  3. Example 3

    Input
    3
    1.00 0.00 1.00
    0.00 1.50 0.50
    -0.50 -0.50 1.00
    
    Expected output
    2.000 2.000
    
  4. Example 4

    Input
    1
    2.00 0.00 2.00
    
    Expected output
    6.000 3.000
    
  5. Example 5

    Input
    1
    3.00 4.00 5.00
    
    Expected output
    15.000 7.500