#P1697. [USACO18JAN] Lifeguards B
[USACO18JAN] Lifeguards B
Background
This problem is translated from deepseek-v3.
Problem Description
Farmer John has opened a swimming pool for his cows, thinking it will help them relax and produce more milk.
To ensure safety, he hired cows as lifeguards, and each cow’s shift covers a continuous time interval during the day. For simplicity, the pool is open every day from time to time , so each shift can be described by two integers: the times when the cow starts and ends her shift. For example, a lifeguard working from time to time covers units of time (note that the endpoints represent time points).
Unfortunately, Farmer John hired extra lifeguard beyond what his budget can support. Given that he must fire exactly lifeguard, what is the maximum total time that can be covered by the remaining lifeguards’ shifts? A time period is considered covered if at least one lifeguard is present.
Input Format
The first line contains (). The next lines each describe one lifeguard, using two integers in the range to represent the start and end times of that lifeguard’s shift. All endpoints are unique. Shifts from different lifeguards may overlap.
Output Format
Output a single number: the maximum total time that can be covered by the remaining lifeguards’ shifts after Farmer John fires lifeguard.
3
5 9
1 4
3 7
7
Hint
Translated by ChatGPT 5