PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#CC0000065. Dãy con tăng với giới hạn bước nhảy (Longest Increasing Subsequence II)
HỌC THEO LỘ TRÌNH
2 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Dãy con tăng với giới hạn bước nhảy (Longest Increasing Subsequence II)
Longest Increasing Subsequence II
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
Given an integer array and a positive integer , find the longest subsequence whose consecutive elements strictly increase and differ by at most . The original order must be preserved.
Input
The first line contains . The second line contains the array . This is the stdin/stdout adaptation of the original LeetCode function problem.
Output
Print the maximum length of a valid subsequence.
Subtasks
Original constraints: ; .
- Subtask 1 (20 points): ; .
- Subtask 2 (30 points): ; .
- Subtask 3 (50 points): ; .
Examples
Input
9 3
4 2 1 4 3 4 5 8 15
Output
5
Explanation
For instance, is valid: successive differences are , all at most . The answer is .