Beetles
Time limit1sMemory limit128 MB
Given n segments, find the smallest axis-aligned square that contains at least k of them entirely, with boundary counted as inside.
- Level
Hard8 of 10
- Topics
- Binary search, Geometry, Sorting, Sliding window
- Solved
- No attempts yet
Problem
Beetles live on a large, square meadow. Each beetle spends its whole life walking back and forth along a segment between two points it has chosen.
You want to catch at least beetles. To do this you will build one square fence and set it down on the meadow; the fence's sides must be parallel to the edges of the meadow (that is, an axis-aligned square). Since you never know where a beetle currently is on its segment, a beetle is guaranteed to be caught only if its entire segment lies inside the fence (the boundary counts as inside). A beetle pinned under the fence's border also counts as caught.
Find the side length of the smallest square fence that can be placed so that at least beetles are guaranteed to be caught, no matter where on their segments the beetles happen to be.
Input
The first line contains two integers and separated by a single space (). Here is the number of beetles and is how many you need to catch.
Each of the next lines describes one beetle's route with four integers separated by single spaces (). The endpoints of that beetle's walking segment are and . A coordinate denotes the point that is away from the western edge and away from the southern edge of the meadow.
Output
Print a single integer: the side length of the smallest fence that meets the requirement.