Road
Practice
4.2 (35 votes)
Dynamic programming
簡単 普通
Algorithms
3 dimensional
Dp
Easy Medium
Problem
33% Success 10572 Attempts 30 Points 2.5s Time Limit 256MB Memory 1024 KB Max Code

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.

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

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
1 votes
Tags:
AlgorithmsDynamic ProgrammingModular arithmeticEasy-Medium
Points:30
5 votes
Tags:
Easy-MediumEasy-med