#abc257h. Ex - Dice Sum 2

Ex - Dice Sum 2

Score : 600600 points

问题描述

六面骰子专卖店“Saikoroya”出售 NN 个骰子。第 ii 个骰子的六个面上分别写着 Ai,1,Ai,2,,Ai,6A_{i,1}, A_{i,2}, \ldots, A_{i,6},其售价为 CiC_i

Takahashi打算从中恰好选择 KK 个骰子购买。

目前,“Saikoroya”正在进行促销活动:Takahashi可以将购买的每个骰子掷一次,并获得与骰子上显示的数字之和平方等额的金钱。这里,每个骰子随机且独立地以相等的概率显示六个数字中的一个。

通过合理选择要购买的 KK 个骰子,最大化(他所获得金额)- (他为购买的 KK 个骰子支付的总金额)的期望值。将最大化的期望值对 998244353998244353 取模后输出。

998244353998244353 下期望值的定义

可以证明所求的期望值始终是一个有理数。此外,在本题的约束条件下,所求的期望值可以用不可约分数 yx\frac{y}{x} 表示,其中 xx 不可被 998244353998244353 整除。

在这种情况下,我们可以唯一确定一个整数 zz,满足 0z9982443520 \leq z \leq 998244352(包括两端点),使得 xzy(mod998244353)xz \equiv y \pmod{998244353}。请输出这样的 zz

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

The six-sided dice speciality shop "Saikoroya" sells NN dice. The ii-th die (singular of dice) has Ai,1,Ai,2,,Ai,6A_{i,1},A_{i,2},\ldots,A_{i,6} written on its each side, and has a price of CiC_i.

Takahashi is going to choose exactly KK of them and buy them.

Currently, "Saikoroya" is conducting a promotion: Takahashi may roll each of the purchased dice once and claim money whose amount is equal to the square of the sum of the numbers shown by the dice. Here, each die shows one of the six numbers uniformly at random and independently.

Maximize the expected value of (the amount of money he claims) - (the sum of money he pays for the purchased KK dice) by properly choosing KK dice to buy. Print the maximized expected value modulo 998244353998244353.

Definition of the expected value modulo 998244353998244353

We can prove that the sought expected value is always a rational number. Moreover, under the Constraints of this problem, the sought expected value can be expressed by an irreducible fraction yx\frac{y}{x} where xx is indivisible by 998244353998244353.

In this case, we can uniquely determine the integer zz between 00 and 998244352998244352 (inclusive) such that xzy(mod998244353)xz \equiv y \pmod{998244353}. Print such zz.

Constraints

  • 1N10001 \leq N \leq 1000
  • 1KN1 \leq K \leq N
  • 1Ci1051 \leq C_i \leq 10^5
  • 1Ai,j1051 \leq A_{i,j} \leq 10^5
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN KK

C1C_1 C2C_2 \ldots CNC_N

A1,1A_{1,1} A1,2A_{1,2} \ldots A1,6A_{1,6}

\vdots

AN,1A_{N,1} AN,2A_{N,2} \ldots AN,6A_{N,6}

Output

Print the answer.

Sample Input 1

3 2
1 2 3
1 1 1 1 1 1
2 2 2 2 2 2
3 3 3 3 3 3

Sample Output 1

20

If he buys the 22-nd and 33-rd dice, the expected value of (the amount of money he claims) - (the sum of money he pays for the purchased KK dice) equals (2+3)2(2+3)=20(2 + 3)^2 - (2 + 3) = 20, which is the maximum expected value.

Sample Input 2

10 5
2 5 6 5 2 1 7 9 7 2
5 5 2 4 7 6
2 2 8 7 7 9
8 1 9 6 10 8
8 6 10 3 3 9
1 10 5 8 1 10
7 8 4 8 6 5
1 10 2 5 1 7
7 4 1 4 5 4
5 10 1 5 1 2
5 1 2 3 6 2

Sample Output 2

1014

update @ 2024/3/10 10:56:40