Maximal polygon brightness
Time limit3sMemory limit1024 MB
Given a convex polygon and a sequence of vertex deletions, compute after each deletion the largest total length of edges that a single external light point can illuminate.
- Level
Hard9 of 10
- Topics
- Geometry, Dynamic programming, Divide and conquer, Greedy
- Solved
- No attempts yet
Problem
A convex polygon lies in the plane. Put a light source at a point outside , and some edges of become lit. If and are two consecutive vertices of , the edge is lit when the area of triangle is not zero and that triangle does not meet the interior of .
The brightness of the polygon is the sum of the lengths of the lit edges. The maximal brightness is the largest brightness you can reach by choosing the best point . The distance between and the polygon is unrestricted, and the coordinates of do not have to be integers.

The polygons , , and from the second example. The figure also marks the maximal brightness.
The vertices of are, in order, . The polygon changes over steps. In step you delete one vertex that is still present and obtain a new polygon . The vertices of are the vertices of that have not been deleted, in the order they had in . Every is convex as well.
Compute the maximal brightness of and of each polygon .
Input
The first line contains the number of vertices of the initial polygon .
The -th of the next lines contains two integers and , the coordinates of vertex ().
The next line contains the number of steps ().
The -th of the next lines contains an integer (), meaning that step deletes vertex .
The vertices of are given counter-clockwise, no two consecutive edges are parallel, and all are distinct.
Output
Print lines.
The first line holds the maximal brightness of the initial polygon . The -th of the next lines holds the maximal brightness of the polygon obtained after step .
Round every value to six decimal places and print all six digits, trailing zeros included. In every test the answer stays far from a rounding boundary, so double precision arithmetic prints the same digits.