A819 | Lifeguards--Platium
来源USACO
时间限制1s
内存限制128MB
通过 / 提交0/0
题目描述
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 $N$ 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 $0$ until time $10^9$ 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 $t = 4$ and
ending at time $t = 7$ covers three units of time (note that the endpoints are
"points" in time).
Unfortunately, Farmer John hired $K$ more lifeguards than he has the funds to
support. Given that he must fire exactly $K$ 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.
them relax and produce more milk.
To ensure safety, he hires $N$ 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 $0$ until time $10^9$ 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 $t = 4$ and
ending at time $t = 7$ covers three units of time (note that the endpoints are
"points" in time).
Unfortunately, Farmer John hired $K$ more lifeguards than he has the funds to
support. Given that he must fire exactly $K$ 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 $N$ and $K$ ($K \leq N \leq 100,000, 1 \leq K
\leq 100$). Each of the next $N$ lines describes a lifeguard in terms of two
integers in the range $0 \ldots 10^9$, giving the starting and ending point of
a lifeguard's shift. All such endpoints are distinct. Shifts of different
lifeguards might overlap.
\leq 100$). Each of the next $N$ lines describes a lifeguard in terms of two
integers in the range $0 \ldots 10^9$, 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 $K$ lifeguards.
be covered if Farmer John fires $K$ lifeguards.
输入输出样例
输入 #1
3 2 1 8 7 15 2 14
输出 #1
12
In this example, FJ should fire the lifeguards covering $1 \ldots 8$ and $7
\ldots 15$.
\ldots 15$.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted