Custom keyboard 2 - MarisaOJ: Marisa Online Judge

Custom keyboard 2

Time limit: 1000 ms
Memory limit: 256 MB
The Ancient Tengu language consists of $m$ different characters, the $i^{th}$ character is denoted as $i$. Rinnosuke wants to type a paragraph $S$ of length $n$ in Acient Tengu language. Marisa wants to build a custom keyboard for him with $m$ keys arranged in a row. The position of each character $c$ in the keyboard is denoted by $p_c$, and the tiredness of typing a paragraph $s$ of $n$ characters is given by the formula: $$\sum_{i=1}^{n - 1} |p_{s_{i + 1}} - p_{s_i}|$$ Marisa wants to minimize the tiredness for Rinnosuke. Please help her determine the minimum tiredness! ### Input - The first line contains 2 integers $n$ and $m$. - The second line contains $n$ integers, denoting the paragraph $S$. ### Output - On the first line, print the minimum tiredness. - On the second line, print the order of the characters on the keyboard. ### Constraints - $1 \le n \le 10^5$. - $1 \le m \le 50$. ### Example Input: ``` 6 3 1 1 3 1 2 3 ``` Output: ``` 5 2 1 3 ``` ### Scoring - All test cases are scored equally. - Consider the jury's answer as $Y$ and your answer as $X$. - If $X$ is less than or equal to $Y$, you receive a score of $100\%$ for test case. - If $1 < \frac{X}{Y} \le 2$, your score for the test case is calculated as $(\frac{2X - Y}{X})^2\times 100 \%$. - If $\frac{X}{Y} > 2$, you receive a score of $0\%$ for the test case.