QOJ.ac

QOJ

Time Limit: 3 s Memory Limit: 512 MB Total points: 100

#6178. 区间子集问题

Statistics

给定实轴上 $n$ 个区间,第 $i$ 个区间为 $[L_i, R_i]$ ($1 \leq i \leq n$)。这 $n$ 个区间的 $2n$ 个区间端点互不相同。由此可知,这 $n$ 个区间中,任何 $2$ 个区间或其交集为空,或有包含关系。

区间子集问题:对于实轴上给定的区间端点互不相同的 $n$ 个区间 $[L_i , R_i ]$ ($1 \leq i \leq n$),从每个子区间 $[L_i, R_i]$ 中选取一个子区间 $[l_i, r_i]$ ($L_i \leq l_i < r_i \leq R_i$),使得选出的任何 $2$ 子区间的交集最多只有 $1$ 个点。要求选出的 $n$ 个子区间的长度之和 $\sum_{i=1}^n (r_i-l_i)$ 达到最大。

输入格式

第一行为一个正整数 $n$。

接下来每行有两个整数,第 $i + 1$ 行给出两个整数 $L_i, R_i$,表示相应区间为 $[L_i, R_i]$。

输出格式

输出计算出的最大子区间的长度和。

样例数据

样例输入

4
1 10
2 3
5 9
6 7

样例输出

7

子任务

测试数据中 $10\%$ 的数据满足 $n \leq 10$ 。

测试数据中 $40\%$ 的数据满足 $n \leq 500$ 。

测试数据中 $100\%$ 的数据满足 $n \leq 2\,000$ 。

About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.