## GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

## Longest Strike Codeforces Solution | Codeforces Problem Solution 2022

F. Longest Strike
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Given an array $a$ of length $n$ and an integer $k$, you are tasked to find any two numbers $l$ and $r$ ($l\le r$) such that:

• For each $x$ $\left(l\le x\le r\right)$$x$ appears in $a$ at least $k$ times (i.e. $k$ or more array elements are equal to $x$).
• The value $r-l$ is maximized.

If no numbers satisfy the conditions, output -1.

For example, if $a=\left[11,11,12,13,13,14,14\right]$ and $k=2$, then:

• for $l=12$$r=14$ the first condition fails because $12$ does not appear at least $k=2$ times.
• 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$.
• for $l=11$$r=11$ the first condition holds, because $11$ occurs at least $k=2$ times in $a$.

A pair of $l$ and $r$ for which the first condition holds and $r-l$ is maximal is $l=13$$r=14$.

Input

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.

Most Similar Words Codeforces Solution

The first line of each test case contains the integers $n$ and $k$ ($1\le n\le 2\cdot {10}^{5}$$1\le k\le n$) — the length of the array $a$ and the minimum amount of times each number in the range $\left[l,r\right]$ should appear respectively.

Then a single line follows, containing $n$ integers describing the array $a$ ($1\le {a}_{i}\le {10}^{9}$).

It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot {10}^{5}$.

Output

For each test case output $2$ numbers, $l$ and $r$ that satisfy the conditions, or "-1" if no numbers satisfy the conditions.

If multiple answers exist, you can output any.