CF1044C Optimal Polygon Perimeter
Description
Furthermore, we define the perimeter of a polygon, as the sum of Manhattan distances between all adjacent pairs of points on it; if the points on the polygon are ordered as $ p\_1, p\_2, \\ldots, p\_k $ $ (k \\geq 3) $ , then the perimeter of the polygon is $ d(p\_1, p\_2) + d(p\_2, p\_3) + \\ldots + d(p\_k, p\_1) $ .
For some parameter $ k $ , let's consider all the polygons that can be formed from the given set of points, having any $ k $ vertices, such that the polygon is not self-intersecting. For each such polygon, let's consider its perimeter. Over all such perimeters, we define $ f(k) $ to be the maximal perimeter.
Please note, when checking whether a polygon is self-intersecting, that the edges of a polygon are still drawn as straight lines. For instance, in the following pictures:
In the middle polygon, the order of points ( $ p\_1, p\_3, p\_2, p\_4 $ ) is not valid, since it is a self-intersecting polygon. The right polygon (whose edges resemble the Manhattan distance) has the same order and is not self-intersecting, but we consider edges as straight lines. The correct way to draw this polygon is ( $ p\_1, p\_2, p\_3, p\_4 $ ), which is the left polygon.
Your task is to compute $ f(3), f(4), \\ldots, f(n) $ . In other words, find the maximum possible perimeter for each possible number of points (i.e. $ 3 $ to $ n$$$).