Sunscreen
InterviewTime limit1sMemory limit128 MB
Each cow accepts an SPF interval, each bottle has an SPF value and capacity; assign bottles to maximize the number of cows covered.
- Level
Medium5 of 10
- Topics
- Greedy, Sorting, Intervals, Two pointers
- Solved
- No attempts yet
Problem
To avoid an unsightly burn while tanning at the beach, each of the cows () must cover her hide with sunscreen. Cow works only with a range of SPF ratings, given by a minimum and a maximum (, ). If the SPF rating is too low the cow gets sunburned; if it is too high the cow does not tan at all.
The cows share a picnic basket holding bottles of sunscreen lotion (). Bottle has an SPF rating () and can be applied to at most cows. Each cow may use lotion from only one bottle.
Cow is protected by bottle if and only if . What is the maximum number of cows that can protect themselves while tanning with the available lotion?
Input
- Line 1: Two space-separated integers, and .
- Lines 2 to : Line describes cow with two integers, and .
- Lines to : Each line describes one lotion bottle with two space-separated integers, and .
Output
Print a single integer: the maximum number of cows that can be protected while tanning.