CF1034D.Intervals of Intervals

NOI/NOI+/CTSC

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Little D is a friend of Little C who loves intervals very much instead of number "33".

Now he has nn intervals on the number axis, the ii-th of which is [ai,bi][a_i,b_i].

Only the nn intervals can not satisfy him. He defines the value of an interval of intervals [l,r][l,r] (1≤l≤r≤n1 \leq l \leq r \leq n, ll and rr are both integers) as the total length of the union of intervals from the ll-th to the rr-th.

He wants to select exactly kk different intervals of intervals such that the sum of their values is maximal. Please help him calculate the maximal sum.

小 D 是小 C 的朋友,他非常喜欢区间,而不是数字“3”。

现在他在数轴上有 nn 个区间,其中第 ii 个区间为 [ai,bi][a_i,b_i]。

仅有这 nn 个区间还不能让他满足。他将一个“区间段” [l,r][l,r](其中 1≤l≤r≤n1 \leq l \leq r \leq n,且 ll、rr 均为整数)的值定义为:第 ll 个到第 rr 个区间(含端点)的并集的总长度。

他希望恰好选出 kk 个互不相同的区间段,使得它们的值之和最大。请帮助他计算这个最大和。

输入格式

First line contains two integers nn and kk (1≤n≤3⋅1051 \leq n \leq 3 \cdot 10^5, 1≤k≤min⁡n(n+1)2,1091 \leq k \leq \min{\frac{n(n+1)}{2},10^9}) — the number of intervals Little D has and the number of intervals of intervals he will select.

Each of the next nn lines contains two integers aia_i and bib_i, the ii-th line of the nn lines describing the ii-th interval (1≤ai<bi≤1091 \leq a_i \lt b_i \leq 10^9).

第一行包含两个整数 nn 和 kk(1≤n≤3⋅1051 \leq n \leq 3 \cdot 10^5,1≤k≤min⁡n(n+1)2,1091 \leq k \leq \min{\frac{n(n+1)}{2},10^9}),分别表示 Little D 拥有的区间数量,以及他将选择的“区间之区间”的数量。

接下来的 nn 行中,每行包含两个整数 aia_i 和 bib_i,其中第 ii 行描述第 ii 个区间(1≤ai<bi≤1091 \leq a_i \lt b_i \leq 10^9)。

输出格式

Print one integer — the maximal sum of values Little D can get.

输出一个整数——小 D 能获得的最大价值总和。

输入输出样例

  • 输入#1

    2 1
    1 3
    2 4

    输出#1

    3
  • 输入#2

    3 3
    1 4
    5 7
    3 6

    输出#2

    15

说明/提示

For the first example, Little D will select [1,2][1,2], the union of the first interval and the second interval is [1,4][1,4], whose length is 33.

For the second example, Little D will select [1,2][1,2], [2,3][2,3] and [1,3][1,3], the answer is 5+6+4=155+6+4=15.

对于第一个例子,小 D 将选择区间 [1,2][1,2],第一个区间与第二个区间的并集为 [1,4][1,4],其长度为 33。

对于第二个例子,小 D 将选择区间 [1,2][1,2]、[2,3][2,3] 和 [1,3][1,3],答案为 5+6+4=155+6+4=15。

输入解题思路,AI测评打分。不知道怎么写?

首页