CF1452E.Two Editorials

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Berland regional ICPC contest has just ended. There were mm participants numbered from 11 to mm, who competed on a problemset of nn problems numbered from 11 to nn.

Now the editorial is about to take place. There are two problem authors, each of them is going to tell the tutorial to exactly kk consecutive tasks of the problemset. The authors choose the segment of kk consecutive tasks for themselves independently of each other. The segments can coincide, intersect or not intersect at all.

The ii-th participant is interested in listening to the tutorial of all consecutive tasks from lil_i to rir_i. Each participant always chooses to listen to only the problem author that tells the tutorials to the maximum number of tasks he is interested in. Let this maximum number be aia_i. No participant can listen to both of the authors, even if their segments don't intersect.

The authors want to choose the segments of kk consecutive tasks for themselves in such a way that the sum of aia_i over all participants is maximized.

Berland 地区 ICPC 竞赛刚刚结束。共有 mm 名参赛者,编号从 11 到 mm,他们共同完成了由 nn 道题目组成的题目集,题目编号从 11 到 nn。

现在即将举行题解讲解环节。共有两位题目作者,每位作者将分别讲解题目集中恰好 kk 道连续题目的题解。两位作者各自独立地为自己选择一段长度为 kk 的连续题目区间。这两段区间可以完全重合、部分相交,也可以互不相交。

第 ii 名参赛者希望听取从第 lil_i 题到第 rir_i 题(含端点)的所有连续题目的题解。每名参赛者总是选择唯一一位作者来听取其讲解——该作者所讲解的题目中,落在 [li,ri][l_i, r_i] 范围内的题目数量最多。记该最大数量为 aia_i。即使两位作者所选区间互不相交,任何一名参赛者也不能同时听取两位作者的讲解。

两位作者希望为自己选择两段长度为 kk 的连续题目区间,使得所有参赛者的 aia_i 之和最大化。

输入格式

The first line contains three integers n,mn, m and kk (1≤n,m≤20001 \le n, m \le 2000, 1≤k≤n1 \le k \le n) — the number of problems, the number of participants and the length of the segment of tasks each of the problem authors plans to tell the tutorial to.

The ii-th of the next mm lines contains two integers lil_i and rir_i (1≤li≤ri≤n1 \le l_i \le r_i \le n) — the segment of tasks the ii-th participant is interested in listening to the tutorial to.

第一行包含三个整数 n,mn, m 和 kk(1≤n,m≤20001 \le n, m \le 2000,1≤k≤n1 \le k \le n)——分别表示题目数量、参与者数量,以及每位题目作者计划讲解的题目区间的长度。

接下来的 mm 行中,第 ii 行包含两个整数 lil_i 和 rir_i(1≤li≤ri≤n1 \le l_i \le r_i \le n)——表示第 ii 位参与者希望听取讲解的题目区间。

输出格式

Print a single integer — the maximum sum of aia_i over all participants.

输出一个整数——所有参与者中 aia_i 的最大和。

输入输出样例

  • 输入#1

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

    输出#1

    14
  • 输入#2

    10 3 3
    2 4
    4 6
    3 5

    输出#2

    8
  • 输入#3

    4 4 1
    3 3
    1 1
    2 2
    4 4

    输出#3

    2
  • 输入#4

    5 4 5
    1 2
    2 3
    3 4
    4 5

    输出#4

    8

说明/提示

In the first example the first author can tell the tutorial to problems from 11 to 33 and the second one — from 66 to 88. That way the sequence of aia_i will be [3,2,3,3,3][3, 2, 3, 3, 3]. Notice that the last participant can't listen to both author, he only chooses the one that tells the maximum number of problems he's interested in.

In the second example the first one can tell problems 22 to 44, the second one — 44 to 66.

In the third example the first one can tell problems 11 to 11, the second one — 22 to 22. Or 44 to 44 and 33 to 33. Every pair of different problems will get the same sum of 22.

In the fourth example the first one can tell problems 11 to 55, the second one — 11 to 55 as well.

在第一个例子中,第一位作者可以讲解第 11 至 33 题,第二位作者可以讲解第 66 至 88 题。这样,序列 aia_i 将为 [3,2,3,3,3][3, 2, 3, 3, 3]。注意:最后一名参与者不能同时听两位作者的讲解,他只会选择其中能为其讲解更多其感兴趣题目的那位作者。

在第二个例子中,第一位作者可以讲解第 22 至 44 题,第二位作者可以讲解第 44 至 66 题。

在第三个例子中,第一位作者可以讲解第 11 题,第二位作者可以讲解第 22 题;或者第一位作者讲解第 44 题,第二位作者讲解第 33 题。任意一对不同的题目所获得的总和均为 22。

在第四个例子中,第一位作者可以讲解第 11 至 55 题,第二位作者也可以讲解第 11 至 55 题。

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

首页