Official

B - Make Many Triangles Editorial by evima


Calculating the answer

This problem asks how many sets of three non-collinear points can be formed. The answer is clearly at most \(\lfloor\frac{N}{3}\rfloor\).

First, let’s consider the case where there is a line \(L\) that contains at least \(N-\lfloor\frac{N}{3}\rfloor+1\) of the \(N\) points. If \(k\) is the number of points not on \(L\), then \(2k \leq N-k\). By combining two points from \(L\) and one point not on \(L\), we can create \(k\) triangles. On the other hand, if we try to create \(k+1\) or more triangles, there will always be a set using three points from \(L\), violating the non-degenerate triangle condition. Therefore, the answer is \(k\).

Next, let’s consider the case where such a line does not exist. In this case, the answer is, in fact, \(\lfloor\frac{N}{3}\rfloor\). If we admit this, then to calculate the answer, we only need to check if such a line exists and count the number of points on that line. Since we only need to consider \(O(N^2)\) lines that pass through at least two of the \(N\) points, we can naively check if the points exist on each line and still do the calculation in \(O(N^3)\) time, which is fast enough.

Proof of the above fact

Now, let’s prove by induction on \(N\) that the answer is \(\lfloor\frac{N}{3}\rfloor\) when the above-mentioned line does not exist. It is clear for \(N=3,4,5\).

Assuming that the above holds for cases with fewer than \(N\) points, we will show that it also holds for \(N\) points. First, take any three points and create a triangle (this is always possible because the above-mentioned line does not exist). If the above-mentioned line does not exist for the remaining \(N-3\) points, the claim can be shown by the induction hypothesis.

So, let’s consider the case where there is a line \(L\) that passes through at least \(N-3-\lfloor\frac{N-3}{3}\rfloor+1\) of the remaining \(N-3\) points. From the assumption that there is no line passing through \(N-\lfloor\frac{N}{3}\rfloor + 1 = N-3-\lfloor\frac{N-3}{3}\rfloor+3\) points, we only need to consider the case where there is a line \(L\) passing through \(N-3-\lfloor\frac{N-3}{3}\rfloor+1\) or \(N-3-\lfloor\frac{N-3}{3}\rfloor+2\) points.

First, consider the case where there is a line \(L\) passing through \(N -\lfloor\frac{N}{3}\rfloor = N-3-\lfloor\frac{N-3}{3}\rfloor+2\) points. In this case, starting from the \(N\) points, we can create \(\lfloor \frac{N}{3} \rfloor\) triangles by combining two points from \(L\) and one point not on \(L\).

Next, consider the case where there is a line \(L\) passing through \(N-1-\lfloor\frac{N}{3}\rfloor = N-3-\lfloor\frac{N-3}{3}\rfloor+1\) points. Among the three points chosen from the \(N\) points, at most one was on \(L\). If one point was taken from \(L\), then \(L\) is a line passing through \(N-\lfloor\frac{N}{3}\rfloor\) of the \(N\) points, and \(\lfloor\frac{N}{3}\rfloor\) triangles can be created as in the previous case. If none of the three points were taken from \(L\), let’s modify it to take two points from \(L\). Now, only \(N-3-\lfloor\frac{N}{3}\rfloor\) points remain on \(L\) after taking three from the \(N\) points, so \(L\) no longer satisfies the condition. Another line satisfying the condition is a line passing through \(\lfloor\frac{N}{3}\rfloor\) points not on \(L\) and one point on \(L\), but this satisfies the condition only if \(N-3-\lfloor\frac{N-3}{3}\rfloor+1 \leq \lfloor\frac{N}{3}\rfloor + 1\), which holds when \(N=6\). In this case, by illustrating the situation, it can be shown that two triangles can be created by appropriately reselecting three points.

posted:
last update: