PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#BS0000242. Dãy con biến thiên nhẹ (Smooth Subsequence)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Dãy con biến thiên nhẹ (Smooth Subsequence)
Smooth Subsequence
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
Given and integer , select a subsequence by deleting any number of elements without rearranging the rest. Selected elements need not be contiguous in the original sequence. Maximize the length subject to an absolute difference of at most between consecutive selected elements. A singleton always qualifies.
Input
The first line contains integers . The second contains integers .
Output
Print the maximum possible length as an integer.
Subtasks
- Subtask 1 (20 points): ; ; for every .
- Subtask 2 (30 points): ; ; for every .
- Subtask 3 (50 points): ; ; for every .
Examples
Input
5 2
2 4 9 3 5
Output
4
Explanation
Indices 1,2,4,5 give with differences 2,1,2. Length five would require selecting every element, including adjacent 4 and 9 whose difference is 5. Thus four is optimal.