luogu#P4983. 忘情
忘情
Background
"Why are you leaving me!"
"Because you can't handle it!"
"I can handle it!"
"Fine, then maintain such a formula for me right now!"
"Why would you give such a nasty thing."
"To annoy you."
"......"
Problem Description
Your , in order to annoy you, specially invited four gurus and one noob!
said: "We need a sum." So we have .
said: "We need an average." So we have .
said: "We need addition, subtraction, multiplication, and division." So we have some nasty combinations.
said: "We also need squaring." So we square it.
The worst said: "Then I'll help you merge them."
So we get the following expression:
$$\frac{\left((\sum\limits_{i=1}^{n}x_i×\bar x)+\bar x\right)^2}{\bar x^2}$$We define the value of a sequence as this expression, where is the number of elements in the sequence.
Given a sequence of length , you now need to split it into segments. The sum of the values of all segments should be as small as possible. Output this minimum value.
Input Format
The first line contains two positive integers and , as defined in the statement.
The next line contains positive integers, giving the value of each element in order.
Output Format
Output one integer, the minimum value.
3 2
1 2 3
32
10 3
1 2 3 4 5 6 7 8 9 10
1140
Hint
- For of the data, .
- For another of the data, it is guaranteed that .
- For of the data, , .
Translated by ChatGPT 5