Sunscreen
Time Limit: 1000MS | Memory Limit: 65536K |
Total Submissions: 10586 | Accepted: 3702 |
Description
To avoid unsightly burns while tanning, each of the C (1 ≤ C ≤ 2500) cows must cover her hide withsunscreen when they're at the beach. Cow i has a minimum and maximum SPF rating (1 ≤ minSPFi ≤ 1,000; minSPFi ≤ maxSPFi ≤ 1,000) that will work. If the SPF rating is too low, the cow sufferssunburn; if the SPF rating is too high, the cow doesn'ttan at all........
The cows have a picnic basket with L (1 ≤ L ≤ 2500) bottles of sunscreen lotion,each bottle i with an SPF rating SPFi (1 ≤ SPFi ≤ 1,000). Lotion bottle i can cover coveri cows with lotion. A cow may lotionfrom only one bottle.
What is the maximum number of cows that can protect themselveswhile tanning given the available lotions?
Input
* Line 1: Two space-separated integers: C and L
* Lines 2..C+1: Line i describes cow i's lotion requires with twointegers: minSPFi and maxSPFi
* Lines C+2..C+L+1:Line i+C+1describes a sunscreen lotion bottle i with space-separated integers: SPFi and coveri
Output
A single line with an integer that is the maximum number of cowsthat can be protected while tanning
SampleInput
3 2
3 10
2 5
1 5
6 2
4 1
SampleOutput
2
Source
算法分析:题意:n个母牛要抹上防晒物品,对防晒物品有系数要求,,给出若干种防晒品的防晒系数和数量,问最多多少奶牛能使用防晒物品。
分析:
牛按最小值升序排序,物品按系数升序排序。维护一个牛最大程度的优先队列,选取规则为最小程度小于当前物品的系数,然后优先对列出队,是否可以选择物品。