## Editorial for TLE '17 Contest 4 P4 - Willson and Target Practice

Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.

Submitting an official solution before solving the problem yourself is a bannable offence.

Author: d

For the first subtask, the triangle can contain at most points. These points are horizontally adjacent. That is, for any pair , the triangle can contain and .

There are possible coordinates, so we can store an array of size , iterate through all possible triangles, find the best , and output the answer.

Time Complexity: , but is possible too.

For the second subtask, we want to check if there is a triangle that can contain both points. We look at the first point, and colour in the possible locations of the second point. This region forms a regular hexagon that is centered at the first point and has side length . If the hexagon contains the second point, the answer is . Otherwise, the answer is . Determining if the second point lies in the hexagon is left as an exercise to the reader.

Note: Unfortunately, the test data for this subtask is weak, and a naive implementation is able to pass.

Time Complexity: An explanation for subtask 3 is a work in progress.

Subtask 4 is intended to reward submissions that could not pass subtask 5.

First, let's make the problem simpler.

We need to find the answer for upward triangles and downward triangles. Let's find the answer for downward triangles. To do this, flip the coordinates, then find the answer for upward triangles.

As a result, we'll need to find the answer for upward triangles on points. Obviously, the first points should be far away from the last points. Let's find the answer for upward triangles.

All upward triangles are completely determined by a coordinate. This is now a problem of finding the maximal coordinate(s) (i.e. if an upward triangle is placed here, it would achieve the maximum number of targets).

If is a maximal coordinate, then is also a maximal coordinate. Therefore, we only need to search through integer coordinates to find a maximal coordinate.

The number of reasonable choices for is . In all other choices of , the coordinate will never hit a target. Therefore, we only need to search through different 's to find a maximal coordinate.

Let's search through a choice of . A target will either do nothing, or create a line segment (i.e. if an upward triangle is placed anywhere on this line segment, then it will contain the target). Then do some difference array stuff to find the point that hits the most targets. (Note: This point could be at the endpoint of a line segment. It's easy to account for this. If a line segment is the interval , it's enough to change this to .)

Note that line segments are created. If you want, you could precompute these line segments in time.

Time Complexity: , but should pass too.