#P7132. 小 L 的零食

小 L 的零食

Description

O2O2 optimization is automatically enabled when submitting.

Little L now wants to put some snacks into a box. However, if the snacks are not stacked steadily, they will fall and break, so Little L wants to find how many stable ways there are to stack snacks.

Each snack can be abstracted as a 1×11\times1 square, and the bottom of the box can be seen as a one-dimensional line segment of length nn. More precisely, the snacks are divided into nn piles, placed in the box from left to right, denoted as pile 1,2,,n1,2,\ldots,n in order. We consider the height hih_i of pile ii to be the number of snacks in this pile, and any pile is allowed to contain no snacks.

We define pile ii to be stable if and only if:

  • himh_i\le m, i.e. the height of this pile does not exceed mm.
  • While satisfying the previous condition, at least one (or both) of the following conditions holds:
    • i=1i=1 or i=ni=n. In this case, one side is the inner wall of the box, so this pile will not fall.
    • max{hi1,hi+1}hidi\color{red}\max\{h_{i-1},h_{i+1}\}\ge h_i-d_i. In this case, among the two neighboring piles, at least one is tall enough to support this pile so that it will not fall.

We define a stable way to stack snacks as a sequence hih_i of length nn such that, when stacking according to this sequence, every pile is stable.

Obviously, the box can hold at most n×mn\times m snacks. We assume Little L has no fewer than n×mn\times m snacks, and it is not necessary to put all snacks into the box. In addition, we assume every snack is exactly the same.

Input Format

There are 22 lines in total.

The first line contains two positive integers n,mn,m.

The second line contains nn integers d1,d2,dnd_1,d_2\ldots,d_n, with the meaning as shown in the red part in the Description.

The two numbers on each line are separated by a single space. The testdata is generated on Windows. There may be extra spaces at the end of a line.

Output Format

Print one integer per line, representing the number of stable ways to stack snacks, modulo 998244353998244353.

3 3
3 1 1 
59
10 13
12 13 1 4 5 9 7 0 3 8 
851695394

Hint

This problem uses the following scoring strategy:
subtask 11(#11\sim{}#88):10%10\%, n,m5n,m\le5;
subtask 22(#99\sim{}#1212):30%30\%, n,m5×102n,m\le5\times10^2;
subtask 33(#1313\sim{}#1616):20%20\%, n,m3×103n,m\le3\times10^3;
subtask 44(#1717\sim{}#2424):40%40\%, n,m7×103n,m\le7\times10^3.
For 100%100\% of the testdata: 1n,m7×1031\le n,m\le7\times10^3, 0dim0\le d_i\le m. You must pass all test points within a subtask to be considered as passing that subtask.

This problem enables subtask dependencies.

Translated by ChatGPT 5