#P6834. [Cnoi2020] 梦原

[Cnoi2020] 梦原

Description

Unfortunately, this tree has not grown up yet, and it only has a root node 11.

Cirno only knows that this tree will have nn nodes, with a1,a2,,ana_1,a_2,\ldots,a_n fruits on them respectively, but she cannot know the shape of the tree.

However, the growth of the tree always follows some pattern.

For node ii, it will choose a node uniformly at random from [ik,i1]N+[i-k,i-1] \cap N^+ to connect to, and become a child of that node.

Here, kk is a constant that Cirno has already measured.

To pick all the fruits, after the tree has grown, Cirno will use magic multiple times. Each time, she chooses a connected subgraph (a connected component) on the tree, and picks one fruit from every node in that connected component (it must be guaranteed that every node in the connected component has at least one fruit).

Obviously, Cirno will use the best strategy to minimize the number of times she uses magic.

Now, Cirno already knows nn, kk, and the number of fruits aia_i that will grow on each node. Please help her compute the expected value of the minimum number of magic uses. For simplicity, you only need to output the remainder of the answer modulo 998244353998244353.

Input Format

The first line contains two integers nn and kk, as described above.

The second line contains nn integers, denoting a1,a2,,ana_1,a_2,\cdots,a_n.

Output Format

Output one line with one integer, denoting the answer.

3 2
2 1 3
499122180
10 1
580461319 261515299 384092031 741339597 746815717 566875585 354719606 821499852 330315651 349091676
553073655
10 9
497873025 114058764 159468194 207476408 138162972 678927661 223886159 325207554 470061543 658861685
180853894

Hint

Explanation of Sample 1.

There are two possible trees as follows (black is the node index, red is the number of fruits on the node):

The best plan is to use magic once on connected component {1,2,3}\{1,2,3\} and once on {1}\{1\}, and use it twice on {3}\{3\}, for a total of 44 times.

The best plan is to use magic once on each of the connected components {1,2,3}\{1,2,3\}, {1,3}\{1,3\}, and {3}\{3\}, for a total of 33 times.

So the answer is 72499122180(mod998244353)\frac{7}{2}\equiv 499122180\pmod{998244353}.

Constraints and Notes

For 100%100\% of the testdata, it is guaranteed that 1k<n1061\le k<n\le 10^6 and 0ai<9982443530\le a_i<998244353.

Subtasks (This problem uses bundled tests.)

  • Subtask 1 (10%10\%): k=1k=1.
  • Subtask 2 (10%10\%): n10n \le 10, ai{0,1}a_i \in \{0,1\}.
  • Subtask 3 (10%10\%): n10n \le 10.
  • Subtask 4 (10%10\%): n1000n \le 1000.
  • Subtask 5 (60%60\%): No additional constraints.

Translated by ChatGPT 5