We have an array a of size n and a number k. There are n points on the plane. We can travel from point i to point j if and only if \(i < j\) and it takes \(|a_i - a_j|\) units of time to move. We should find the maximal number of points (including start point) we can visit in one journey if we start from point 1 (you can not start from any other point except point 1)and end at any arbitrary point and we will use at most k units of time in this journey.
\(\textbf{Input}\)
The first line contains 2 integers - \(n \; (1 \le n \le 10^5\)) and \(k \; (0 \le k \le 50\)).
The second line contains n integers - \(a_1, a_2, a_3, \dots, a_n \; (0 \le a_i \le 50\)) separated by space.
\(\textbf{Output}\)
Output the maximal number of points you can visit under the conditions mentioned above.
4 5 1 2 50 6
3
Go from point 1 to point 2 using \(|1 - 2| = 1\) unit of time, and from 2 to 4 using \(|2 - 6| = 4\) units of time.
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor
Login to unlock the editorial
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor