#P2439. [SDOI2005] 阶梯教室设备利用

[SDOI2005] 阶梯教室设备利用

Description

{{We have many talks to be held in a lecture hall. Each talk is determined by a unique start time and end time. If two talks overlap partially or entirely, they cannot be held simultaneously in the lecture hall. We want to make the best possible use of this hall; that is, we need to select some non-overlapping talks so that their total scheduled time is as long as possible. We assume that at the exact moment one talk ends, another talk can start immediately.

Write a program to:

Read all start and end times of the talks and compute the maximum possible total time of talks.}}

Input Format

{{The first line contains a positive integer nn, the number of talks.

Each of the following nn lines contains two space-separated integers pp and kk. Such a pair indicates a talk that starts at time pp and ends at time kk.}}

Output Format

{{Output a single integer, the maximum total time of the talks.}}

12
1 2
3 5
0 4
6 8
7 13
4 6
9 10
9 12
11 14
15 19
14 16
18 20

16

Hint

{{Sample Explanation

You can choose the 3rd, 5th, 6th, 11th, and 12th talks, yielding the maximum total duration 1616.

Constraints

1n1041 \le n \le 10^4, 0p<k3×1040 \le p < k \le 3 \times 10^4.}}

Translated by ChatGPT 5