题目描述
Problem Description
There are \( t \) moments, and for each moment \( i \), the situation \( p_1, p_2, \dots, p_{s_i} \) is given, indicating that within the range \((0, d)\) on the number line, there are exactly \( p_1, p_2, \dots, p_{s_i} \) positions occupied by items.
At positions \( 0 \) and \( d \), there are infinitely many items.
You can spend a cost to move an item one position to the left or to the right.
Determine the minimum cost required to transform the situation from one moment to the next.
Input Format
The first line contains two positive integers \( n \) and \( d \).
The next \( n \) lines describe the situation for each moment. Each line starts with a non-negative integer \( s_i \), followed by \( s_i \) positive integers \( p_1, p_2, \dots, p_{s_i} \). It is guaranteed that \( 0 < p_1 < p_2 < \dots < p_{s_i} < d \).
Output Format
\( n-1 \) lines, each containing a single integer, which is your answer.
Sample Input and Output
Sample Input #1
3 10
2 4 7
3 3 6 8
1 5
Sample Output #1
4
6
Sample Input #2
(Refer to the attached file)
Sample Output #2
6252500
6252500
Sample Input #3
(Refer to the attached file)
Sample Output #3
999990000
999990000
999990000
999990000
Sample Input #4
(Generator: /paste/3igmip11)
Sample Output #4
(Generator: /paste/fusadpm0)
Notes
For all data, \( 2 \leq n \leq 500000 \), \( 2 \leq d \leq 10^{12} \), \( \sum s_i \leq 500000 \).
| Subtask Number | Additional Constraints | Points |
|---|---|---|
| 1 | \( s_i \leq 1 \) | 5 |
| 2 | \( s_i \leq 3 \) | 10 |
| 3 | \( d \leq 7 \) | 12 |
| 4 | \( \sum s_i \leq 5000 \) | 27 |
| 5 | If \( s_i > 0 \), then \( p_{s_i} = p_1 + s_i - 1 \) | 11 |
| 6 | 35 |
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分