#P7962. [NOIP2021] 方差
[NOIP2021] 方差
Problem Description
Given a non-strictly increasing sequence of positive integers of length : . In each operation, you may choose any positive integer and change to . After performing some operations, find the minimum possible variance of the sequence. Output the result of the minimum variance multiplied by .
The variance is defined as the average of the squared differences between each number and the mean. More formally, the variance is $D = \frac{1}{n} \sum_{i = 1}^{n} {(a_i - \bar a)}^2$, where .
Input Format
The first line contains a positive integer , and it is guaranteed that .
The second line contains positive integers, where the -th number is . The testdata guarantees that .
Output Format
Output a single line containing a non-negative integer, which is the minimum variance you can obtain multiplied by .
4
1 2 4 6
52
见附件中的 variance/variance2.in
见附件中的 variance/variance2.ans
见附件中的 variance/variance3.in
见附件中的 variance/variance3.ans
见附件中的 variance/variance4.in
见附件中的 variance/variance4.ans
Hint
Sample Explanation #1
For , after the first operation, the possible sequence is . After the second operation, the new sequence is . After that, no new sequence can be obtained.
For , the mean is , and the variance is $\frac{1}{4}({(1 - \frac{13}{4})}^2 + {(2 - \frac{13}{4})}^2 + {(4 - \frac{13}{4})}^2 + {(6 - \frac{13}{4})}^2) = \frac{59}{16}$.
For , the mean is , and the variance is $\frac{1}{4} ({(1 - \frac{7}{2})}^2 + {(3 - \frac{7}{2})}^2 + {(4 - \frac{7}{2})}^2 + {(6 - \frac{7}{2})}^2) = \frac{13}{4}$.
For , the mean is , and the variance is $\frac{1}{4} ({(1 - \frac{15}{4})}^2 + {(3 - \frac{15}{4})}^2 + {(5 - \frac{15}{4})}^2 + {(6 - \frac{15}{4})}^2) = \frac{59}{16}$.
Constraints
| Test Point ID | ||
|---|---|---|
For all testdata, it is guaranteed that and .
Translated by ChatGPT 5