#P12134. Smooth Art Exhibition Arrangement
Smooth Art Exhibition Arrangement
Smooth Art Exhibition Arrangement
Curator Xiaolan and her assistant Xiaoqiao are preparing an art exhibition with N paintings, each having art values \(A_1, A_2, \dots, A_N\). They need to choose exactly M paintings from the collection and arrange them in a specific order in the exhibition hall.
A random selection and arrangement might lead to abrupt changes in art values and a less than smooth viewing experience. To optimize the layout, they refer to the Exhibition Arrangement Guide, which recommends that the ideal exhibition minimizes the abrupt transitions between the paintings. The guide defines a metric \(L\) as:
\(L = \sum_{i=1}^{M-1} \left|B_{i+1}^2 - B_i^2\right|\),
where \(B_i\) denotes the art value of the painting placed at the i-th position. The smaller \(L\) is, the smoother the transition between the paintings.
Your task is to select and arrange M paintings such that \(L\) is minimized, and output the minimum possible value of \(L\).
inputFormat
The first line contains two integers N and M (1 ≤ M ≤ N ≤ 10^5
), where N is the total number of paintings, and M is the number of paintings to be selected.
The second line contains N integers: A1, A2, ..., AN (1 ≤ Ai ≤ 10^9
), representing the art values of the paintings.
outputFormat
Output a single integer: the minimum possible value of \(L\) when the M paintings are chosen and arranged optimally.
sample
5 3
2 3 8 1 4
8