Ryu, a literal street fighter is about to take on $N$ opponents (numbered from $0$ to $N-1$) on Wah Yan Street, each rival has a fighting style denoted by an integer $S_i$ $(0\le i\le N-1)$.
Ryu has already taken down the first opponent (opponent $0$) of fighting style $S_0$ to initiate the battle, and he plans to take down the rest of the opponents in order, from opponent $1$ to opponent $N-1$.
However, Ryu can only defeat opponent $j$ if he has previously defeated an opponent of "similar" fighting style. Two fighting styles are considered similar if they differ by at most $k$, where $k$ is Ryu's skill level.
Formally, he can defeat an opponent $j$ if and only if he has previously defeated some opponent $i$ $(i\lt j)$ such that $|S_i-S_j|\le k$.
Help deduce whether Ryu can defeat all $N$ opponents in order, or otherwise deduce which opponent he would be defeated by.
Input
The first line contains two integers, $N$ and $k$.
The next line contains $N$ integers, where the $i$-th integer is $S_i$, the fighting style of the $i$-th opponent.
Output
Output Winner if he defeats all $N$ opponents, or output an integer $x$, the index of the opponent he is defeated by.
Constraints
For all cases, $2\le N\le 2 \cdot 10^5, 1\le k,S_i\le 10^9$
Subtask 1 (40%): $N\le1000$
Subtask 2 (60%): No additional constraints
Sample Test Cases
| Input | Output | |
|---|---|---|
| 3 2 1 3 5 |
Winner | |
| 6 3 10 7 13 4 5 17 |
5 | |
For opponent at index $j = 5$ with style $S_5 = 17$, all previously defeated opponents ($S_0 = 10$, $S_1 = 7$, $S_2 = 13$, $S_3 = 4$, $S_4 = 5$) have $|S_i - S_5| > k = 3$, making opponent $S_5$ undefeatable. |
||
Scoring: Per Subtask
Authored by s19x17
Appeared in 2025 Wah Yan Interschool Olympiad in Informatics 🤯🥷⚡🧠🏆