luogu#P4182. [USACO18JAN] Lifeguards P
[USACO18JAN] Lifeguards P
题目描述
Farmer John has opened a swimming pool for his cows, figuring it will help them relax and produce more milk.
To ensure safety, he hires cows as lifeguards, each of which has a shift that covers some contiguous interval of time during the day. For simplicity, the pool is open from time until time on a daily basis, so each shift can be described by two integers, giving the time at which a cow starts and ends her shift. For example, a lifeguard starting at time and ending at time covers three units of time (note that the endpoints are "points" in time).
Unfortunately, Farmer John hired more lifeguards than he has the funds to support. Given that he must fire exactly lifeguards, what is the maximum amount of time that can still be covered by the shifts of the remaining lifeguards? An interval of time is covered if at least one lifeguard is present.
输入格式
The first line of input contains and (). Each of the next lines describes a lifeguard in terms of two integers in the range , giving the starting and ending point of a lifeguard's shift. All such endpoints are distinct. Shifts of different lifeguards might overlap.
输出格式
Please write a single number, giving the maximum amount of time that can still be covered if Farmer John fires lifeguards.
题目大意
给定 个左开右闭区间 ,求去除其中的 个后剩下的区间的并集最多可以覆盖多少个整数。
$1\le n\le 10^5,1\le k\le \min(n,100),0\le l_i\le r_i\le 10^9$,保证 互不相同。
3 2
1 8
7 15
2 14
12
提示
In this example, FJ should fire the lifeguards covering and .