Kは多角形のケイ
Time limit8sMemory limit512 MB
Given N integer points, find the perimeter of the K-th shortest simple polygon with vertices at those points that contains all N points, or print -1 if there are fewer than K.
- Level
Medium4 of 10
- Topics
- Geometry, Implementation
- Solved
- No attempts yet
Problem
"1 ban ja nakya dame desu ka? K ban ja dame na n deshou ka?" This is Kei's motto. Lately Kei seems fixated on polygons, and looking at points spread across a wide two-dimensional plane, Kei keeps thinking about how to form a polygon from them.
Kei picks some of the points and connects them in any order, so that the chosen points are the vertices of a polygon. The polygon must satisfy these conditions:
- It is a simple polygon. That is, it has at least 3 vertices, and no two edges that are not consecutive share a point.
- All points, including the ones not chosen, lie inside or on the boundary of the polygon.
Kei wants the polygon whose perimeter, the sum of all edge lengths, is the -th shortest among such polygons.
Your task is to help Kei. Among the polygons that satisfy the conditions, sort them by perimeter in ascending order and output the perimeter of the -th one. If there are fewer than such polygons, output instead.
Input
The input consists of multiple datasets. Each dataset has the following format.
N K
x1 y1
...
xN yN
The first line of a dataset gives the number of points and the rank of the perimeter to find. Both and are integers, and , . The next lines give the coordinates of each point. On line , the x coordinate and the y coordinate are integers. For all , .
You may assume that no line passes through any three distinct points. You may also assume that if the polygon with the -th smallest perimeter exists, it is uniquely determined.
The input ends with a line containing two zeros. The total number of datasets does not exceed 50.
Output
For each dataset, output on one line the perimeter of the -th shortest simple polygon that can be formed from the given points. If no such polygon exists, output -1. The result must have an error of less than .