Polygon Game
Limits: 2 sec., 256 MiB
This statement was translated automatically from Ukrainian.
Zenyk and Marichka are experienced skaters. They don’t want to just skate around, so they came up with the following game.
Before the game starts, Zenyk virtuously draws a convex \(n\)-gon on the ice with his skates.
When the polygon is ready, the players take turns. Marichka goes first.
In one turn, a player can choose a diagonal of the polygon and skate along it, cutting the ice. The diagonal will split the polygon into two smaller polygons. Then the player chooses one of the two parts on which the game will continue. This ends the turn.
The game ends when a triangle remains.
Marichka wants to maximize the area of the remaining triangle, and Zenyk wants to minimize it.
What will the area be under optimal play by both players?
Input
The first line contains an integer \(n\) — the number of vertices of the polygon.
The next \(n\) lines contain two integers \(x_i\), \(y_i\) each — the coordinates of the vertices of the polygon in counterclockwise order.
Output
Print an integer — twice the area of the triangle remaining after the game ends.
It can be proven that twice the area of a triangle with integer coordinates is an integer.
Constraints
\(4 \le n \le 10^5\),
\(|x_i|, |y_i| \le 10^9\),
no three vertices of the polygon are collinear.
7 points: \(n \le 15\);
8 points: \(n \le 10^3\);
10 points: no additional constraints.
Samples
| Input (stdin) | Output (stdout) |
|---|---|
| 4 0 0 7 4 3 11 -4 7 | 65 |
| Input (stdin) | Output (stdout) |
|---|---|
| 20 -20 5 -20 1 -19 -3 -17 -7 -15 -9 -13 -10 -11 -10 5 -8 12 -7 15 -6 17 -4 18 -1 18 3 17 6 15 8 12 9 8 9 -5 8 -14 7 -19 6 | 4 |
Notes
In the first example, the game will end after Marichka’s first move. Regardless of which diagonal she chooses, the square will be divided into two equal triangles.
In the second example, one of the possible scenarios is as follows. Marichka cuts the diagonal between the vertices \((-15, -9)\) and \((5, -8)\) (purple) and leaves the upper part for the game. Zenyk draws the diagonal between the vertices \((-20, 5)\) and \((-19, -3)\) (green) and leaves the triangle. The game ends here.
Submit a solution
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|
Polygon Game - Editorial
The triangle with the smallest area built on the vertices of a convex polygon consists of three consecutive vertices of the polygon. To prove this, we use the formula for the area of a triangle: the area is half the product of the length of a base and the length of the height dropped onto it.
If we take a triangle that does not consist of three consecutive vertices, fix two of them and move the third one in one of the two directions along the vertices of the polygon, the height decreases, so the area of the triangle decreases too. This can be continued until the vertices of the triangle are consecutive vertices of the polygon. In the picture, the areas of the triangles \(ABD\) and \(ABE\) are less than the area of the triangle \(ABC\), since the distances from the points \(D\) and \(E\) to the line \(AB\) are less than the distance from the point \(C\) to this line.
Now let’s see how Zenyk plays. Since he wants to minimize the area of the triangle, on his move he simply chooses the smallest triangle of three consecutive vertices of the polygon and cuts the polygon along the corresponding diagonal. This ends the game.
Marichka, knowing that Zenyk will always end the game with his move, has no reason to let him choose the triangle with the smallest area, so on her move she chooses the largest triangle of three consecutive vertices of the polygon. So Marichka can end the game on the first move.
The answer is the largest area of a triangle of three consecutive vertices of the polygon.
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|