codeforces-scrape

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

1676F.md (1970B)


      1 Source: https://codeforces.com/problemset/problem/1676/F
      2 
      3 F. Longest Strike
      4 
      5 time limit per test
      6 
      7 1 second
      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 Given an array $a$ of length $n$ and an integer $k$, you are tasked to find any two numbers $l$ and $r$ ($l \leq r$) such that:
     22 
     23 * For each $x$ $(l \leq x \leq r)$, $x$ appears in $a$ at least $k$ times (i.e. $k$ or more array elements are equal to $x$).
     24 * The value $r-l$ is maximized.
     25 
     26 If no numbers satisfy the conditions, output -1.
     27 
     28 For example, if $a=[11, 11, 12, 13, 13, 14, 14]$ and $k=2$, then:
     29 
     30 * for $l=12$, $r=14$ the first condition fails because $12$ does not appear at least $k=2$ times.
     31 * for $l=13$, $r=14$ the first condition holds, because $13$ occurs at least $k=2$ times in $a$ and $14$ occurs at least $k=2$ times in $a$.
     32 * for $l=11$, $r=11$ the first condition holds, because $11$ occurs at least $k=2$ times in $a$.
     33 
     34 A pair of $l$ and $r$ for which the first condition holds and $r-l$ is maximal is $l = 13$, $r = 14$.
     35 
     36 Input
     37 
     38 The first line of the input contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases. The description of test cases follows.
     39 
     40 The first line of each test case contains the integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5$, $1 \leq k \leq n$) — the length of the array $a$ and the minimum amount of times each number in the range $[l, r]$ should appear respectively.
     41 
     42 Then a single line follows, containing $n$ integers describing the array $a$ ($1 \leq a_i \leq 10^9$).
     43 
     44 It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
     45 
     46 Output
     47 
     48 For each test case output $2$ numbers, $l$ and $r$ that satisfy the conditions, or "-1" if no numbers satisfy the conditions.
     49 
     50 If multiple answers exist, you can output any.
     51 
     52 Example
     53 
     54 Input
     55 
     56 ```
     57 4
     58 
     59 7 2
     60 
     61 11 11 12 13 13 14 14
     62 
     63 5 1
     64 
     65 6 3 5 2 1
     66 
     67 6 4
     68 
     69 4 3 4 3 3 4
     70 
     71 14 2
     72 
     73 1 1 2 2 2 3 3 3 3 4 4 4 4 4
     74 ```
     75 
     76 Output
     77 
     78 ```
     79 13 14
     80 1 3
     81 -1
     82 1 4
     83 ```