Repeatedly remove the interior point whose triangle area is smallest, breaking ties by original index, and report each removal index.
Medium7HeapLinked listSimulationGeometryNo attempts yetTime limit5sMemory limit512 MBMapping applications represent the boundaries of countries and cities as polylines, which are connected sequences of line segments. Fine details have to be shown when the user zooms in, so such a polyline often contains a very large number of segments. When the user zooms out, those details do not matter, and processing and drawing a polyline with that many segments is wasteful. This problem uses one polyline simplification algorithm that approximates the original polyline with a polyline that has fewer segments.
A polyline with n segments is described by n+1 points p0=(x0,y0),…,pn=(xn,yn), where the ith segment joins pi−1 and pi. Removing an interior point pi (1≤i≤n−1) simplifies the polyline: the segments pi−1pi and pipi+1 are replaced by the single segment pi−1pi+1. Choose the point to remove like this. For every interior point pi, compute the area of the triangle formed by pi−1, pi and pi+1 (the area is 0 when the three points are colinear), and remove the point whose triangle has the smallest area. When several points have the smallest area, remove the one with the smallest index in the original polyline. Apply the same rule to the resulting polyline again, until the desired number m of segments is left.
The figure below shows one step.

The original polyline is at the top. In the middle, the area of the triangle formed by p2, p3 and p4 is measured, and p3 is removed when that area is the smallest among all such triangles. The bottom shows the polyline after p3 is removed.
The first line contains two integers n (2≤n≤200000) and m (1≤m<n). Each of the next n+1 lines describes one point, giving p0 through pn in order. A line holds the x and y coordinates of the point, both integers between −5000 and 5000 inclusive. The points are strictly increasing in lexicographic order. That is, for every 0≤i<n, either xi<xi+1, or xi=xi+1 and yi<yi+1.
Print n−m lines. On the kth line print the index of the point removed in the kth step of the algorithm above. Use the index the point has in the original polyline.