Fence
Time limit2sMemory limit1024 MB
Given a convex polygon and one interior post, find a maximum-area polygon whose vertices are these posts, with no other post strictly inside it.
- Level
Hard8 of 10
- Topics
- Geometry, Dynamic programming
- Solved
- No attempts yet
Problem
The fence around Princeton-Plainsboro Hospital was built long before Dr. House, Dr. Cuddy, and the rest of the current staff arrived. The fence is a convex polygon. Posts stand at its vertices, and its edges are fence sections. By mistake, an extra post was built inside the fence, that is, on hospital grounds, and it has caused the staff and patients a lot of trouble.
Dr. Cuddy wants to fix this by building a new fence around the hospital. The new fence must satisfy three conditions:
- The vertices of the new fence polygon can only be existing posts (the vertices of the old fence and the one post inside it).
- No post that is not a vertex of the new polygon may lie inside it.
- Its area must be as large as possible.
The new fence polygon may be non-convex, and some posts outside its area may stay unused.
Input
The first line contains one integer (), the number of vertices of the old fence polygon. Each of the next lines contains two integers and , with absolute values not exceeding , the coordinates of a vertex. The coordinates are given in counterclockwise order, and the polygon is convex. No three vertices lie on one line.
The last line contains two integers and , with absolute values not exceeding , the coordinates of the extra post. It is guaranteed that the point lies strictly inside the polygon.
Output
Print the polygon of the new fence in the same format as the old one: the number of vertices on the first line, followed by the coordinates of each vertex on its own line. No post that is not a vertex may lie strictly inside the new fence, and its area must be maximal.