Разбор
The general observation for every group is that the -coordinate does not matter since both coordinates do not depend on each other when performing the maneuvers (it can be seen from the formula of your new coordinate) and the only condition about reaching the Link-Cut system does not depend on . Thus, the problem can be reduced to its -dimensional case.
Group 1.
In this group, there are only two cases to handle:
: in this case, no maneuvers are needed since you have already reached the Link-Cut system;
: in this case, you can reach the needed -coordinate using only one maneuver with the first and the second meteors. Here is why:
(because the arithmetic mean of two numbers is at least as large as the minimal one of them);
and ;
, and this is exactly what we need.
Thus, the answer in this group is either , if your initial position is in the Link-Cut system, or otherwise.
Time and memory complexity: or (it is not necessary to read all the points, the first two of them are enough)
Group 2.
Here is the observation that will be used in this and in the next groups: to reach the needed -coordinate, the most optimal strategy is to alternate performing maneuvers using two leftmost meteors and two rightmost ones.
Also, there are two possible ways of using the above strategy: to begin from the left or from the right side.
Let's name the midpoint between two leftmost meteors as , the midpoint between the rightmost one as and your initial position as . Then:
If initially holds, then after the first maneuver will be either or
After each maneuver, either or will increase by , and the distance from to either or respectively will remain unchanged, depending on the side, relative to which the new maneuver is done.
Since and increases each by after every two maneuvers, and the side on which lays relative to and alternates after each maneuver, the needed coordinate will either be reached after a finite number of maneuvers if , or will not be reached otherwise.
It can be seen that the number of maneuvers will be in case of non-zero . In this group, since , the possible solution is to simulate the process of performing maneuvers from both sides and to take the best answer out of two cases of the first maneuver.
Group 3.
This group was added to make the fast implementations of the previous group and the quiet inaccurate implementations of the full solution get more points.
Group 4. no additional constraints
The solution for this group is based on the solution for the second one, but there is also the observation that helps to solve it a lot faster. If we write down our -coordinate after each maneuver we perform and separate them by odd and even positions, two arithmetic series will be formed. That holds because the distances increase exactly by after every two operations, which can be considered as a step of arithmetic series. This way, the problem is being reduced to finding the index of the first arithmetic progression term that is (and taking the minimum such index out of two series).