Under construction

Still being built. Things may change

Cruise

Time limit2sMemory limit512 MB

Summary
Choose a closed polygonal cruise from Piraeus through the islands so that collected point value divided by route length is maximized.
Level

Hard8 of 10

Topics
Geometry, Dynamic programming, Binary search, Greedy
Solved
No attempts yet

Problem

A group of computer science students gathers in Athens for the summer holidays. While working out how to see the Aegean sea by sailboat, they invented the following game.

  • Every island has one point value assigned to it.
  • The cruise starts at the port of Piraeus and returns to it. Piraeus sits at (0,0)(0, 0), and every island lies strictly east of Piraeus.
  • A course leg is a straight segment from one island to another island or to Piraeus. Apart from Piraeus, the cruise may pass through any point of the Aegean sea at most once.
  • The team collects the points of every island the course passes through and of every island inside the area the course encloses. An island lying on the course counts as collected.
  • The goal is to maximize the ratio RR of collected points over the total length of the cruise.

Given the coordinates and the point value of each island, find the ratio RR of the optimal cruise.

Suppose there are six islands, A through F, placed as in the figure below. Piraeus is marked P in the figures. For example, island B is at (4,2)(4, 2) and its point value is 66.

The next three figures show three courses that start at Piraeus and return there. Below each figure is the ratio RR of that course. Of the three, the leftmost course has the largest RR. The rightmost course also collects the points of island E, which lies inside the enclosed area.

Route P, A, B, C, PRoute P, C, E, F, PRoute P, C, F, P
R=5+6+22+8+2+32≃1.041226R = \frac{5+6+2}{2+\sqrt{8}+2+\sqrt{32}} \simeq 1.041226R=2+5+632+5+2+17≃0.967965R = \frac{2+5+6}{\sqrt{32}+\sqrt{5}+\sqrt{2}+\sqrt{17}} \simeq 0.967965R=2+5+632+3+17≃1.017218R = \frac{2+5+6}{\sqrt{32}+3+\sqrt{17}} \simeq 1.017218

The courses P, B, E, C, F, E, P and P, B, F, C, P break the rules. The first passes through island E twice, and the second passes twice through the intersection of segment BF and segment CP.

Input

The first line contains the number of islands NN. Each of the next NN lines contains three integers XiX_i, YiY_i, PiP_i: the coordinates (Xi,Yi)(X_i, Y_i) of the ii-th island and the point value PiP_i assigned to it.

Output

Print the ratio RR of the optimal cruise on one line, rounded to six decimal places.

Constraints

  • 2≤N≤1002 \le N \le 100
  • 0<Xi≤100000 < X_i \le 10000
  • −10000≤Yi≤10000-10000 \le Y_i \le 10000
  • 0≤Pi≤100000 \le P_i \le 10000
  • No two islands share the same coordinates.
  • At least two islands lie in different directions as seen from Piraeus. No input places every island on a single ray out of Piraeus, so at least one legal cruise always exists.

Examples2

  1. Example 1

    Input
    6
    2 0 5
    4 2 6
    4 4 2
    2 6 1
    2 3 5
    1 4 6
    
    Expected output
    1.751999
    
  2. Example 2

    Input
    2
    1 0 10
    1 1 10
    
    Expected output
    5.857864