CF1055E.Segments on the Line

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are a given a list of integers a1,a2,…,ana_1, a_2, \ldots, a_n and ss of its segments [lj;rj][l_j; r_j] (where 1≤lj≤rj≤n1 \le l_j \le r_j \le n).

You need to select exactly mm segments in such a way that the kk-th order statistic of the multiset of aia_i, where ii is contained in at least one segment, is the smallest possible. If it's impossible to select a set of mm segments in such a way that the multiset contains at least kk elements, print -1.

The kk-th order statistic of a multiset is the value of the kk-th element after sorting the multiset in non-descending order.

给定一个整数列表 a1,a2,…,ana_1, a_2, \ldots, a_n,以及该列表的 ss 个区间 [lj;rj][l_j; r_j](其中 1≤lj≤rj≤n1 \le l_j \le r_j \le n)。

你需要恰好选择 mm 个区间,使得所有被至少一个所选区间覆盖的下标 ii 对应的 aia_i 构成的多重集的第 kk 小值尽可能小。如果无法选出 mm 个区间,使得该多重集包含至少 kk 个元素,则输出 -1。

一个多重集的第 kk 小值(即第 kk 阶统计量)是指将该多重集按非降序排序后,第 kk 个位置上的元素值。

输入格式

The first line contains four integers nn, ss, mm and kk (1≤m≤s≤15001 \le m \le s \le 1500, 1≤k≤n≤15001 \le k \le n \le 1500) — the size of the list, the number of segments, the number of segments to choose and the statistic number.

The second line contains nn integers aia_i (1≤ai≤1091 \le a_i \le 10^9) — the values of the numbers in the list.

Each of the next ss lines contains two integers lil_i and rir_i (1≤li≤ri≤n1 \le l_i \le r_i \le n) — the endpoints of the segments.

It is possible that some segments coincide.

第一行包含四个整数 nn、ss、mm 和 kk(1≤m≤s≤15001 \le m \le s \le 1500,1≤k≤n≤15001 \le k \le n \le 1500)——分别表示列表的大小、线段总数、需选择的线段数量以及统计序号。

第二行包含 nn 个整数 aia_i(1≤ai≤1091 \le a_i \le 10^9)——表示列表中各数字的值。

接下来的 ss 行,每行包含两个整数 lil_i 和 rir_i(1≤li≤ri≤n1 \le l_i \le r_i \le n)——表示第 ii 条线段的左右端点。

某些线段可能完全重合。

输出格式

Print exactly one integer — the smallest possible kk-th order statistic, or -1 if it's impossible to choose segments in a way that the multiset contains at least kk elements.

输出一个整数——即可能的最小的第 kk 小元素;如果无法选择线段,使得多重集包含至少 kk 个元素,则输出 −1-1。

输入输出样例

  • 输入#1

    4 3 2 2
    3 1 3 2
    1 2
    2 3
    4 4

    输出#1

    2
  • 输入#2

    5 2 1 1
    1 2 3 4 5
    2 4
    1 5

    输出#2

    1
  • 输入#3

    5 3 3 5
    5 5 2 1 1
    1 2
    2 3
    3 4

    输出#3

    -1

说明/提示

In the first example, one possible solution is to choose the first and the third segment. Together they will cover three elements of the list (all, except for the third one). This way the 22-nd order statistic for the covered elements is 22.

在第一个例子中,一种可能的解法是选择第一个和第三个区间。它们共同覆盖了列表中的三个元素(除第三个元素外的所有元素)。这样,被覆盖元素的第 22 小值为 22。

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

首页