Quadrilaterals
Time limit1.7sMemory limit512 MB
Given n points with no three collinear, find the maximum total credit from all quadrilaterals, where convex and minimum-area shapes score more.
- Level
Hard9 of 10
- Topics
- Geometry, Sorting, Divide and conquer
- Solved
- No attempts yet
Problem
A quadrilateral is a polygon with exactly four distinct corners and four distinct sides, with no crossing between its sides. A quadrilateral is called convex if all the inner angles at its corners are less than 180 degrees. Otherwise it is non-convex. The illustration below shows a convex quadrilateral (left) and a non-convex quadrilateral (right).

In a test problem, you are given a set of points in the plane. No three points in are collinear. Your task is to find as many quadrilaterals as possible by connecting four points from . Each point in can be used any number of times, and the quadrilaterals you find may overlap each other. You earn credits for each quadrilateral based on its shape and area. Convex quadrilaterals and quadrilaterals with minimum area earn more.
Let be the minimum area over all quadrilaterals that can be formed by connecting four points in . The credits are as follows.
- Each distinct convex quadrilateral with area exactly earns 4 credits.
- Each distinct non-convex quadrilateral with area exactly earns 3 credits.
- Each distinct convex quadrilateral with area strictly larger than earns 2 credits.
- Each distinct non-convex quadrilateral with area strictly larger than earns 1 credit.
Two quadrilaterals are distinct unless their corners and sides are exactly the same. There may be two or more quadrilaterals with the minimum area .
Given , write a program that outputs the maximum total credits you can earn by finding all possible quadrilaterals from .
Input
The first line contains an integer (), the number of points in . Each of the next lines contains two integers, the x and y coordinates of a point in . Each coordinate is between and , inclusive. No three points in are collinear.
Output
Print one line containing a single integer, the maximum total credits you can earn from .