Official

G - Isosceles Trapezium Editorial by en_translator


Two edges form the opposite sides of a isosceles trapezium if and only if all the following conditions is satisfied:

  • The perpendicular bisector of the edges are the same
  • The midpoints of the edges are not the same

From this observation, we come up with the following solution.

Enumerate all the possible edges and store them with the data of:

  • the perpendicular bisector of the edge;
  • the midpoint of the edge;
  • the sum of the weights.

Then classify them by their perpendicular bisector.

Take one group of edges with the same perpendicular bisector. How can we obtain the answer within this group?
Since we always use the edge with the maximum sum of weights, we actually can obtain the answer.

Therefore, the problem has been solved.
The time complexity is \(O(N^2 \log N)\), where the classification by the perpendicular bisectors is the bottleneck.


When using decimal types, be very careful of the computational errors. For this problem, we think it would be safer to use only integer types.

Also, note that some edges or perpendicular bisectors have slopes of \(0\) or \(\infinity\).
We can either divide into cases, or treat lines in a form of \(ax+by+c=0\) instead of \(y=ax+b\).

posted:
last update: