codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

977C.md (1517B)


      1 Source: https://codeforces.com/problemset/problem/977/C
      2 
      3 C. Less or Equal
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 You are given a sequence of integers of length $n$ and integer number $k$. You should print any integer number $x$ in the range of $[1; 10^9]$ (i.e. $1 \le x \le 10^9$) such that exactly $k$ elements of given sequence are less than or equal to $x$.
     22 
     23 Note that the sequence can contain equal elements.
     24 
     25 If there is no such $x$, print "-1" (without quotes).
     26 
     27 Input
     28 
     29 The first line of the input contains integer numbers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5$, $0 \le k \le n$). The second line of the input contains $n$ integer numbers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) — the sequence itself.
     30 
     31 Output
     32 
     33 Print any integer number $x$ from range $[1; 10^9]$ such that exactly $k$ elements of given sequence is less or equal to $x$.
     34 
     35 If there is no such $x$, print "-1" (without quotes).
     36 
     37 Examples
     38 
     39 Input
     40 
     41 ```
     42 7 4  
     43 3 7 5 1 10 3 20
     44 ```
     45 
     46 Output
     47 
     48 ```
     49 6
     50 ```
     51 
     52 Input
     53 
     54 ```
     55 7 2  
     56 3 7 5 1 10 3 20
     57 ```
     58 
     59 Output
     60 
     61 ```
     62 -1
     63 ```
     64 
     65 Note
     66 
     67 In the first example $5$ is also a valid answer because the elements with indices $[1, 3, 4, 6]$ is less than or equal to $5$ and obviously less than or equal to $6$.
     68 
     69 In the second example you cannot choose any number that only $2$ elements of the given sequence will be less than or equal to this number because $3$ elements of the given sequence will be also less than or equal to this number.