#P8591. 『JROI-8』颅脑损伤 2.0

    ID: 9344 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>动态规划 DP2022洛谷原创O2优化洛谷月赛

『JROI-8』颅脑损伤 2.0

Problem Description

Given nn line segments, where the ii-th segment is [li,ri][l_i,r_i]. Color each segment either red or black, with the following requirements:

  1. Any two red segments do not intersect.
  2. Any black segment intersects with at least one red segment.

Minimize the total length of the red segments, and output this total length.

The length of a segment [li,ri][l_i,r_i] is defined as rilir_i-l_i. Two segments [li,ri][l_i,r_i] and [lj,rj][l_j,r_j] intersect if and only if lirjl_i\le r_j and ljril_j\le r_i.

Input Format

The first line contains one positive integer nn.

The next nn lines each contain two integers li,ril_i,r_i, separated by a space.

Output Format

Output one non-negative integer, representing the minimum possible total length of the red segments.

5
-6 5
1 3
-4 9
-1 10
6 8

4

Hint

Constraints

Test Point ID nn\le
141\sim4 1010
585\sim8 400400
9209\sim20 30003000

For all testdata, 109li<ri109-10^9\le l_i<r_i\le10^9.

Translated by ChatGPT 5