Almost Sorted 2

AtCoder
IDabc431_f
Time2000ms
Memory256MB
Difficulty
You are given an integer sequence $A=(A_1,A_2,\ldots,A_N)$ of length $N$ and a positive integer $D$. Find the number, modulo $998244353$, of integer sequences $B=(B_1, B_2, \ldots, B_N)$ that can be obtained by rearranging $A$ and satisfy the following condition: * $B_{i+1}\geq B_i-D$ holds for all $i\ (1\leq i\leq N-1)$. ## Constraints * $2\leq N\leq 2\times 10^5$ * $1\leq D\leq 10^6$ * $1\leq A_i\leq 10^6$ * 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 1
5 2 1 2
Output #1
3

The integer sequences satisfying the condition are $(1,2,2,5),(2,1,2,5),(2,2,1,5)$, which are three sequences.
Input #2
5 10
20 40 60 80 100
Output #2
1
Input #3
15 12345
18270 31252 27543 31406 22271 13402 12279 25697 18349 27615 39360 22790 32581 23990 36154
Output #3
858152905
API Response (JSON)
{
  "problem": {
    "name": "Almost Sorted 2",
    "description": {
      "content": "You are given an integer sequence $A=(A_1,A_2,\\ldots,A_N)$ of length $N$ and a positive integer $D$. Find the number, modulo $998244353$, of integer sequences $B=(B_1, B_2, \\ldots, B_N)$ that can be o",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "abc431_f"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "You are given an integer sequence $A=(A_1,A_2,\\ldots,A_N)$ of length $N$ and a positive integer $D$.\nFind the number, modulo $998244353$, of integer sequences $B=(B_1, B_2, \\ldots, B_N)$ that can be o...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments