#P10888. Minimum Subject Weight Requirement

    ID: 12932 Type: Default 1000ms 256MiB

Minimum Subject Weight Requirement

Minimum Subject Weight Requirement

There are \(n\) students (numbered \(1\) to \(n\)) taking an exam in \(m\) subjects (numbered \(1\) to \(m\)). Student \(i\) scores \(a_{i,j}\) in subject \(j\). You want to rank the students based on a weighted total score. To do so, you assign non‐negative real weights \(p_1, p_2, \dots, p_m\) to the subjects such that \(\sum_{j=1}^{m} p_j = 1\). The weighted total score for student \(i\) is defined as

[ S_i = \sum_{j=1}^{m} a_{i,j},p_j. ]

The students are then ranked in descending order of \(S_i\) (ties are considered equal). However, the teacher of each subject \(k\) requires that in the final ranking there is no pair of distinct students \((x, y)\) such that:

  • Student \(x\) is strictly ranked higher than student \(y\), yet \(a_{x,k} < a_{y,k}\);

You are free to choose the weights \(p_j\), but you want to maximize the flexibility in assigning the other weights. Therefore, for each subject \(k\) \( (1 \le k \le m)\), determine the minimum value of \(p_k\) (modulo \(998244353\)) that guarantees no matter how the other weights are chosen (subject to being nonnegative and summing to \(1-p_k\)), the teacher \(k\)'s requirement is satisfied.

More formally, for each subject \(k\), you need to compute the minimum \(p_k\) such that for any choice of \(p_j \ge 0\) (for \(j \neq k\)) satisfying \(\sum_{j\neq k} p_j = 1 - p_k\), the following holds: For every pair of distinct students \(x,y\) with \(a_{x,k} < a_{y,k}\), it is guaranteed that

[ p_k(a_{y,k}-a_{x,k}) \ge (1-p_k),D_{x,y,k}, ]

where

[ D_{x,y,k} = \max_{\substack{1\le j \le m\ j\neq k}} \max(0,,a_{x,j}-a_{y,j}). ]

This inequality can be rearranged into

[ p_k \ge \frac{D_{x,y,k}}{(a_{y,k}-a_{x,k})+D_{x,y,k}}. ]

You must choose \(p_k\) so that the inequality holds for every pair \((x, y)\) with \(a_{x,k} < a_{y,k}\). If no such pair exists for a subject \(k\), the answer for that subject is \(0\).

All answers should be given modulo \(998244353\).

inputFormat

The first line contains two integers \(n\) and \(m\) \((1 \leq n, m \leq \text{constraints})\), representing the number of students and the number of subjects respectively.

Then \(n\) lines follow, each containing \(m\) integers. The \(j\)-th integer in the \(i\)-th line represents \(a_{i,j}\), the score of student \(i\) in subject \(j\).

outputFormat

Output \(m\) integers separated by spaces. The \(k\)-th integer is the minimum required value of \(p_k\) modulo \(998244353\).

sample

3 2
1 2
2 1
1 1
499122177 499122177