Frontier
Time limit1sMemory limit128 MB
Choose a subset of the polygon's vertices, in clockwise order, forming a convex polygon that strictly contains all given points, minimizing its perimeter.
- Level
Hard8 of 10
- Topics
- Geometry, Dynamic programming, Greedy, Brute force
- Solved
- No attempts yet
Problem

The frontier of Lilliputia is a convex polygon with non-zero area. Its vertices are guard towers joined by straight walls. The frontier is long and expensive to maintain, so the government wants to shorten it. No new towers may be built: the revised frontier must reuse existing towers as its vertices.
Every day the guards inspect the frontier, walking clockwise from one tower to the next. The towers are numbered through in this clockwise inspection order. The revision must keep this same inspection order, and the area enclosed by Lilliputia must stay non-zero. A valid new frontier is therefore any subset of the towers, taken in their original clockwise order, that forms a convex polygon of non-zero area (at least three towers that are not all collinear).
Lilliputia also has historical monuments that are a great source of national pride. Every monument must remain strictly inside Lilliputia; a monument may never lie on the frontier itself. Design the shortest possible frontier that keeps every monument strictly inside.
In the figure above (coordinates in kilometers), the original route 1 → 2 → 3 → 4 → 5 → 1 is 57.89 km long. With no monuments to protect, the shortest revision is 2 → 3 → 4 → 2, only 27.31 km. If the two monuments marked "A" and "B" must stay inside, the shortest valid frontier is 1 → 2 → 3 → 4 → 1, with length 51.78 km.
Input
The first line contains two integers and separated by a space. () is the number of guard towers on the frontier, and () is the number of historical monuments inside Lilliputia.
The next lines give the towers' coordinates in clockwise order, followed by lines giving the monuments' coordinates. Every coordinate is two integers and separated by a space, measured in kilometers, with absolute value at most . All towers are at distinct points, and every monument lies strictly inside the original frontier.
Output
Print a single real number: the minimum possible length of the frontier, in kilometers, rounded to exactly two digits after the decimal point.