#P13993. 【MX-X19-T2】「LAOI-14」SPECIALZ
【MX-X19-T2】「LAOI-14」SPECIALZ
Description
Given positive integers and a positive integer sequence .
There is a robot in an by non-negative integer matrix . The rows are numbered and the columns are numbered . Let the current position of the robot be , with initial position . The robot cyclically performs the following operations:
- Teleport to the position of $\displaystyle \max_{i=\max(y-k_x,1)}^{\min(y+k_x,m)} A_{x,i} [i \ne y]$ (the constraints and that is a permutation of as mentioned below ensure that this position exists and is unique).
In other words, within the same row, from the current position, consider the positions to the left up to columns and to the right up to columns (excluding the current position itself; if the boundaries are reached, stop at the boundaries), then teleport to the position with the maximum value.
- Move down one step. If this move exceeds the matrix size, the loop terminates.
A matrix is considered legal if and only if each row () is a permutation of .
Now, please determine, for all legal matrices , the minimum possible sum of all that the robot passes through. Note that the initial position is also considered as passed by the robot.
Input Format
The first line contains two positive integers .
The second line contains positive integers .
Output Format
Output one line containing an integer, which is the answer.
2 4
2 1
8
2 2
1 1
6
Hint
【Sample Explanation #1】
When , , there exists a corresponding matrix that achieves the minimum value:
$$\begin{bmatrix} 1 & 3 & 2 & 4 \\ 2 & 1 & 3 & 4 \\ \end{bmatrix}$$The robot will pass through positions , , , and in sequence. The sum of is . It can be proven that no better solution exists.
【Data Range】
| Test Case ID | ||
|---|---|---|
For all test cases, , .
Translated by DeepSeek V3.1
京公网安备 11011102002149号