Smooth Subsequence

AtCoder
IDabc339_e
Time2000ms
Memory256MB
Difficulty
You are given a sequence $A = (A_1, A_2, \ldots, A_N)$ of length $N$. Find the maximum length of a subsequence of $A$ such that the absolute difference between any two adjacent terms is at most $D$. A subsequence of a sequence $A$ is a sequence that can be obtained by deleting zero or more elements from $A$ and arranging the remaining elements in their original order. ## Constraints * $1 \leq N \leq 5 \times 10^5$ * $0 \leq D \leq 5 \times 10^5$ * $1 \leq A_i \leq 5 \times 10^5$ * All input values are integers. ## Input The input is given from Standard Input in the following format: $N$ $D$ $A_1$ $A_2$ $\ldots$ $A_N$ [samples]
Samples
Input #1
4 2
3 5 1 2
Output #1
3

The subsequence $(3, 1, 2)$ of $A$ has absolute differences of at most $2$ between adjacent terms.
Input #2
5 10
10 20 100 110 120
Output #2
3
Input #3
11 7
21 10 3 19 28 12 11 3 3 15 16
Output #3
6
API Response (JSON)
{
  "problem": {
    "name": "Smooth Subsequence",
    "description": {
      "content": "You are given a sequence $A = (A_1, A_2, \\ldots, A_N)$ of length $N$. Find the maximum length of a subsequence of $A$ such that the absolute difference between any two adjacent terms is at most $D$. A",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "abc339_e"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "You are given a sequence $A = (A_1, A_2, \\ldots, A_N)$ of length $N$.\nFind the maximum length of a subsequence of $A$ such that the absolute difference between any two adjacent terms is at most $D$.\nA...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments