CF1055E.Segments on the Line

普及/提高-

通过率:0%

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 1ljrjn1 \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.

输入格式

The first line contains four integers nn , ss , mm and kk ( 1ms15001 \le m \le s \le 1500 , 1kn15001 \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 ( 1ai1091 \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 ( 1lirin1 \le l_i \le r_i \le n ) — the endpoints of the segments.

It is possible that some segments coincide.

输出格式

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.

输入输出样例

  • 输入#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 .

首页