CF1055E.Segments on the Line
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are a given a list of integers a1,a2,…,an and s of its segments [lj;rj] (where 1≤lj≤rj≤n ).
You need to select exactly m segments in such a way that the k -th order statistic of the multiset of ai , where i is contained in at least one segment, is the smallest possible. If it's impossible to select a set of m segments in such a way that the multiset contains at least k elements, print -1.
The k -th order statistic of a multiset is the value of the k -th element after sorting the multiset in non-descending order.
输入格式
The first line contains four integers n , s , m and k ( 1≤m≤s≤1500 , 1≤k≤n≤1500 ) — the size of the list, the number of segments, the number of segments to choose and the statistic number.
The second line contains n integers ai ( 1≤ai≤109 ) — the values of the numbers in the list.
Each of the next s lines contains two integers li and ri ( 1≤li≤ri≤n ) — the endpoints of the segments.
It is possible that some segments coincide.
输出格式
Print exactly one integer — the smallest possible k -th order statistic, or -1 if it's impossible to choose segments in a way that the multiset contains at least k elements.
输入输出样例
输入#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 2 -nd order statistic for the covered elements is 2 .