# Gym103627E - Yet Another Interval Graph Problem

## #题面

### #题目描述

You are given $N$ closed intervals. The $i$-th interval covers $[s_i, e_i]$ and has a positive integer weight $w_i$. Consider the undirected graph of $N$ vertices, where each vertex corresponds to an interval, and there exists an edge between two vertices if and only if the corresponding pair of intervals has a nonempty intersection. For a given list of intervals, we call this graph the interval graph.

Jaehyun wants the graph to not have a connected component of size greater than $K$. To accomplish this, he can delete zero or more intervals. Jaehyun is lazy, so over all possible ways to delete intervals, he will select the way that minimizes the weight of the intervals he has to delete. Print the weight of the deleted intervals after he has made sure all connected components of the interval graph have size at most $K$.

### #输入格式

The first line contains two integers $N$ and $K$ ($1 \le K \le N \le 2500$).

Each of the next $N$ lines contains three integers $s_i, e_i, w_i$ ($1 \le s_i \le e_i \le 10^9$, $1 \le w_i \le 10^{9}$).

### #输出格式

Output the sum of the weights of the deleted intervals after Jaehyun’s deletions.

### #输入输出样例

5 2
1 4 1
3 6 2
5 8 5
7 10 2
9 12 1


3


One possible solution is to remove the second and fifth intervals.

## #思路

$n$ 个区间 $[l_i, r_i]$，每个区间有个权值 $w_i$。将这 $n$ 个区间当成 $n$ 个点，如果两个区间它们之间有交（包括端点），那么就在这两个区间之间连边。现在需要删除一些区间，使得每个连通块大小不超过 $k$。输出删除区间最小的权值和。

$f_i$ 表示当前切到位置 $i$，然后枚举上⼀段切的位置 $j$，然后考虑 $[i, j]$ 之间的区间只保留价值最⼤的 $k$ 个，将其他的区间都删掉，但是复杂度是 $O(n^3 \log n)$ 级别的，无法通过本题。