Military Base

Xem dạng PDF

Gửi bài giải

Điểm: 0,01
Giới hạn thời gian: 3.0s
Giới hạn bộ nhớ: 512M
Input: stdin
Output: stdout

Tác giả:
Dạng bài
Ngôn ngữ cho phép
C, C++, Go, Java, Kotlin, Pascal, PyPy, Python, Rust, Scratch

A disputed territory is defined by ~N~ strategic beacons located at coordinate points on a map. These ~N~ points form a strictly convex polygon.

General Sterling and Colonel Vance have been tasked with establishing a new military base within this territory. Their strategic doctrines, however, are opposed:

  • General Sterling advocates for dominance and wants to establish the border to maximize the enclosed area.

  • Colonel Vance prioritizes efficiency and defense, aiming to minimize the enclosed area.

To resolve this disagreement, they agree to a strict protocol to define the base's perimeter:

  • General Sterling and Colonel Vance take turns negotiating to select a subset of points from the N vertices of the territory to choose as vertices for the base.

  • First, General Sterling will go first and select a point as the starting point.

  • In each subsequent turn, the negotiating person will choose a point from the remaining points to draw a line connecting to the previously selected point, with the condition that this line must not intersect with any lines that have already been drawn, and the line from this point to the starting point must also not intersect any other lines.

  • The negotiation only ends when there are no more points that can be selected, and the two connect the last point to the first point to form a smaller convex polygon and choose it as the military base.

Both individuals are skilled strategists, each knows how to negotiate to optimize their own goals. You are a subordinate of these two and wants to know the result early to plan for the construction of the military base. Calculate the area of the base that these two will draw.

Input

The first line contains a positive integer ~T~ (~1 \leq T \leq 100~) — the number of test cases. The test cases are described as follows:

The first line contains a positive integer ~N~ (~1 \leq N \leq 5000~) — the number of coordinate points on the map.

The second line contains ~N~ positive integers ~x_i~ which are the x-coordinates of the points on the map (~-10^9 \leq x_i \leq 10^9~).

The third line contains ~N~ positive integers ~y_i~ which are the y-coordinates of the points on the map (~-10^9 \leq y_i \leq 10^9~).

The test case guarantees that the points on the coordinates form a convex polygon. The order of the points is arranged in a counterclockwise direction of the convex polygon.

The data guarantees that the total ~\sum{n}~ does not exceed ~5000~.

Output

For each test case, return a single value which is the predicted area that will be drawn. The answer returned should be the area multiplied by ~2~.

It can be proven that the returned answer is an integer.

Sample Input 1

2
4
3 8 5 -2
-7 -5 1 7
5
4 -5 -8 -9 1
-4 5 5 4 -3

Sample Output 1

80
41

Notes

Once vertices 2 and 4 are established, General Sterling selects Point 1 to maximize the resulting area. This choice yields a value of 80, which is bigger to the alternative of 24 (~80 > 24~). Consequently, this is also how the negotiation will play out, as illustrated below.

image


Bình luận

Hãy đọc nội quy trước khi bình luận.


Không có bình luận tại thời điểm này.