~/algor $ cat problems/minmax-30-maksimumning-k-chi-uchrashi
K-th occurrence of the maximum
Easy
1000 ms
128 MB
28%
Positive integers $N$, $K$ and $N$ integers are given. Among the elements equal to the largest value, find the position (indexed from $1$) of the $K$-th one counting from the left. If the largest value occurs fewer than $K$ times, print $0$.
Input
The first line contains two positive integers: $N$ and $K$. The next line contains $N$ integers $A_{i}$.
Output
One integer — the position or $0$.
Note
$1 \le K \le N \le 1000$
$-10^{9} \le A_{i} \le 10^{9}$
Examples
Input #1
7 2 4 9 1 9 3 9 2
Output #1
4
Input #2
4 3 5 8 8 1
Output #2
0