#P8458. Treasure Contribution Maximization
Treasure Contribution Maximization
Treasure Contribution Maximization
You are given n divers. The i-th diver collects l₍ᵢ₎ treasures with values (a_{i,1}, a_{i,2}, \ldots, a_{i,l_i}). For each diver, his sequence is repeated a certain number of times so that the resulting sequence, denoted as (a'i), has length k (i.e. the sequence is repeated exactly (\frac{k}{l_i}) times, and k is guaranteed to be divisible by each (l_i)).
For any pair of divers (i) and (j) (with (1 \le i < j \le n)), their combined contribution is defined as
[
g(i,j) = \sum{p=1}^{k} a'{i,p} \times a'{j,p}.
]
Your task is to compute the maximum contribution among all pairs of divers modulo (998244353).
Note: Since the sequences are obtained by repetition, the p-th element of (a'i) is (a{i, (p-1 \bmod l_i)+1}).
inputFormat
The first line contains two integers n and k.
Then n groups follow, each representing a diver’s collection:
- The first integer of each group is \(l_i\) (the number of treasures collected by the i-th diver).
- Then \(l_i\) integers follow, representing \(a_{i,1}, a_{i,2}, \ldots, a_{i,l_i}\).
outputFormat
Output a single integer: the maximum value of (g(i,j)) modulo (998244353) among all pairs (1 \le i < j \le n).
sample
2 6
2 1 2
3 3 4 5
36
</p>