Crime Scene
InterviewTime limit2sMemory limit1024 MB
Given a convex polygon with some fence sides missing, find the minimum total length of missing sides that a tape of length l walked along the boundary cannot cover.
- Level
Medium5 of 10
- Topics
- Sliding window, Two pointers, Prefix sum, Geometry
- Solved
- No attempts yet
Statement
Inspector Lestrade is not a gifted deducer, but he has mastered every detail of routine police work. Oddly, many standard procedures can hide a mystery as worthy of attention as the crime itself.
One evening the inspector arrived at the crime scene, a fenced vacant lot. The lot is a convex polygon with posts standing at its vertices. Apparently, there used to be a fence section between every two posts at adjacent vertices. Time has passed, however, and some fence sections have vanished without a trace. The inspector noticed that every missing section still has its neighboring sections standing.
Lestrade then set about closing off the scene with police tape. He discovered a serious problem: he has only meters of tape left. The inspector does not want to cut the tape into pieces, and the tape must lie only along the perimeter of the lot. He will fix one end of the tape at a point on the boundary, walk meters along the boundary in one of two directions, and fix the other end at the point where he stops. Every part of the boundary he walked past is covered by tape, and every other part is not.
Lestrade wants to know the minimum total length of the boundary with no fence that he cannot cover with tape. Help him, because Sherlock Holmes will arrive soon.
Input
The first line contains three integers , , and (, , ): the number of polygon vertices, the length of the tape, and the number of missing fence sections. The second line contains integers (, ). Each means the side between vertices and has no fence. No two consecutive sides are missing. The next lines each contain integers and (, ), the coordinates of the -th vertex. The vertices are given in order around the polygon in one of the two traversal directions.
Output
Print one real number: the minimum total length of the missing fence sections that the tape cannot cover. The answer is accepted if it differs from the correct value by at most , where is the perimeter of the polygon.