Largest Fence
Time limit2sMemory limit128 MB
Given N grid points with no three collinear, find the size of the largest subset whose points form the vertices of a convex polygon.
- Level
Hard9 of 10
- Topics
- Geometry, Dynamic programming, Sorting, Combinatorics
- Solved
- No attempts yet
Problem
A farmer has bought fence posts and wants to arrange some of them into a good-looking fence. The nicest fences are convex polygons whose vertices are fence posts.
The field is a grid. Post stands at integer coordinates with and . All posts are at distinct positions, and no three posts are collinear.
Choose a subset of the posts to be the vertices of a single convex polygon, so that every chosen post is a corner (vertex) of that polygon. What is the largest number of posts such a convex polygon can use?
Constraints
- No three posts lie on a common line.
Input
- The first line contains a single integer .
- Each of the next lines contains two space-separated integers and : the coordinates of post .
Output
- Print a single integer: the maximum number of posts that can form the vertices of a convex polygon.
Hint
For the sample field, the largest convex polygon is the pentagon with vertices , , , , . The remaining post at cannot be added without making the polygon non-convex, so the answer is .