#P16788. [蓝桥杯 2026 国 A] 独立三角形

    ID: 19129 远端评测题 2000ms 512MiB 尝试: 0 已通过: 0 显示难度普及+/提高− 上传者: 标签>数学枚举2026蓝桥杯国赛

[蓝桥杯 2026 国 A] 独立三角形

Problem Description

There are NN distinct integer points on a 2D plane. Each point has a yy-coordinate of either 11 or 1-1. Xiaolan wants to connect these points to form as many triangles as possible. Each triangle must satisfy:

  • The three vertices must not be collinear.
  • Different triangles must not share vertices.

Since when a point is used as a vertex of a triangle, it will be connected to the other two vertices, each point can be an endpoint of at most two line segments.

Now, under the condition that the number of triangles is maximized, find the maximum possible sum of the areas of all triangles. The problem guarantees that this maximum area sum is an integer.

Input Format

The first line contains an integer NN.

The next NN lines each contain two integers xi,yix_i, y_i, representing the coordinates of a point. It is guaranteed that yi=1|y_i| = 1, and no two points coincide.

Output Format

Output one line containing two integers: the maximum number of triangles that can be formed, and the maximum possible sum of areas under that maximum number of triangles.

3
0 1
2 1
1 -1
1 2
6
0 1
3 1
1 1
1 -1
2 -1
4 -1
2 6

Hint

Sample Explanation 1

The three points can form one triangle. Using the two upper points as the base, the base length is 22, and the distance between the upper and lower lines is 22, so the area is 12×2×2=2\frac{1}{2} \times 2 \times 2 = 2.

Sample Explanation 2

The xx-coordinates of the points with y=1y = 1 are 0,1,30, 1, 3, and the xx-coordinates of the points with y=1y = -1 are 1,2,41, 2, 4. At most 22 triangles without shared vertices can be formed.

One optimal plan is: use the two upper points with x=0x = 0 and 33 as the base of one triangle, with area 33; use the two lower points with x=1x = 1 and 44 as the base of another triangle, also with area 33. The total area is 66.

Constraints and Notes for Evaluation

For 30%30\% of the testdata, 1N3001 \le N \le 300.

For all testdata, 1N2×1051 \le N \le 2 \times 10^5, and xi109|x_i| \le 10^9.

Translated by ChatGPT 5