#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 NN 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 t=0t=0 to time t=1000t=1000, 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 t=4t=4 to time t=7t=7 covers 33 units of time (note that the endpoints represent time points).

Unfortunately, Farmer John hired 11 extra lifeguard beyond what his budget can support. Given that he must fire exactly 11 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 NN (1N1001 \leq N \leq 100). The next NN lines each describe one lifeguard, using two integers in the range 010000 \ldots 1000 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 11 lifeguard.

3
5 9
1 4
3 7
7

Hint

Translated by ChatGPT 5