UberOA #47
Maximum Riders in Car
估计中等可在线判题
考点(AI 标注)前缀和区间
Passenger i is only willing to ride with between low[i] and high[i] other passengers. You may choose any subset of passengers to ride together, and every member must be within their own range. Find the maximum number of passengers; the empty set is valid.
This site has made the standard input and output explicit.
输入格式
The first line contains n, followed by n lines of low high; 1≤n≤100000, 0≤low≤high≤n.
输出格式
Output one integer, the answer.
样例 1
输入:
4
1 3
2 4
0 2
1 3
输出:
3
样例 2
输入:
3
0 2
0 2
0 2
输出:
3
样例 3
输入:
2
2 2
2 2
输出:
0
样例说明
Example 1: with 3 riders you can pick any three passengers whose ranges cover 2; with 4 riders only 3 ranges cover 3, so the maximum is 3. Example 2: all three accept the other two, so the answer is 3. Example 3: both require 2 others, but there are only 2 people in total, so the answer is 0; this also corrects the original third example, where high=3 exceeded n=2, an invalid range.