import
java.util.*;
class
Pair {
int
first;
int
second;
public
Pair(
int
x,
int
y)
{
this
.first = x;
this
.second = y;
}
}
class
GFG {
static
ArrayList<Pair> aux_arr;
static
void
make_aux_array(
int
arr[],
int
n)
{
aux_arr =
new
ArrayList<Pair>();
for
(
int
i =
0
; i < n; i++) {
aux_arr.add(
new
Pair(arr[i], i));
}
aux_arr.sort((a, b) -> (-a.first + b.first));
}
static
int
binarySearch(
int
arr[],
int
n,
int
x)
{
int
position = aux_arr.size() -
1
;
for
(
int
i =
0
; i < aux_arr.size(); i++) {
Pair elem = aux_arr.get(i);
if
(elem.first >= x && elem.second >=
0
)
position = i;
}
if
(position < n
&& aux_arr.get(position).first == x) {
return
aux_arr.get(position).second;
}
else
{
return
-
1
;
}
}
static
void
print(
int
arr[],
int
n,
int
x)
{
make_aux_array(arr, n);
int
result = binarySearch(arr, n, x);
if
(result == -
1
) {
System.out.println(-
1
);
}
else
{
System.out.println(result);
}
}
public
static
void
main(String[] args)
{
int
[] arr
= {
15
,
12
,
13
,
19
,
11
,
10
,
18
,
17
,
14
,
16
};
int
N = arr.length;
int
X =
18
;
print(arr, N, X);
}
}