Under construction

Still being built. Things may change

Polyline Simplification

Time limit5sMemory limit512 MB

Summary
Repeatedly remove the interior point whose triangle area is smallest, breaking ties by original index, and report each removal index.
Level

Medium7 of 10

Topics
Heap, Linked list, Simulation, Geometry
Solved
No attempts yet

Problem

Mapping 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 nn segments is described by n+1n + 1 points p0=(x0,y0),…,pn=(xn,yn)p_0 = (x_0, y_0), \dots, p_n = (x_n, y_n), where the iith segment joins pi−1p_{i-1} and pip_i. Removing an interior point pip_i (1≤i≤n−11 \le i \le n - 1) simplifies the polyline: the segments pi−1pip_{i-1}p_i and pipi+1p_i p_{i+1} are replaced by the single segment pi−1pi+1p_{i-1}p_{i+1}. Choose the point to remove like this. For every interior point pip_i, compute the area of the triangle formed by pi−1p_{i-1}, pip_i and pi+1p_{i+1} (the area is 00 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 mm 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 p2p_2, p3p_3 and p4p_4 is measured, and p3p_3 is removed when that area is the smallest among all such triangles. The bottom shows the polyline after p3p_3 is removed.

Input

The first line contains two integers nn (2≤n≤200 0002 \le n \le 200\,000) and mm (1≤m<n1 \le m < n). Each of the next n+1n + 1 lines describes one point, giving p0p_0 through pnp_n in order. A line holds the xx and yy coordinates of the point, both integers between −5000-5000 and 50005000 inclusive. The points are strictly increasing in lexicographic order. That is, for every 0≤i<n0 \le i < n, either xi<xi+1x_i < x_{i+1}, or xi=xi+1x_i = x_{i+1} and yi<yi+1y_i < y_{i+1}.

Output

Print n−mn - m lines. On the kkth line print the index of the point removed in the kkth step of the algorithm above. Use the index the point has in the original polyline.

Examples2

  1. Example 1

    Input
    10 7
    0 0
    1 10
    2 20
    25 17
    32 19
    33 5
    40 10
    50 13
    65 27
    75 22
    85 17
    
    Expected output
    1
    9
    6
    
  2. Example 2

    Input
    6 1
    0 0
    1 2
    2 4
    3 6
    4 8
    5 10
    6 12
    
    Expected output
    1
    2
    3
    4
    5