#P4072. [SDOI2016] 征途
[SDOI2016] 征途
Description
Pine starts a journey from to .
The road from to can be divided into segments, and there is a rest station at the boundary point between each pair of adjacent segments.
Pine plans to reach in days. Except for day , Pine must spend each night at a rest station. Therefore, each segment must be completed within a single day.
Pine wants the daily distances to be as similar as possible, so he wants the variance of the daily distances to be as small as possible.
Help Pine find the minimum possible variance.
Let the variance be . It can be proven that is an integer. To avoid precision errors, output .
Input Format
The first line contains two integers .
The second line contains integers, representing the lengths of the segments.
Output Format
Output a single integer: the minimum variance multiplied by .
5 2
1 2 5 8 6
36
Hint
- Constraints and Conventions
- For of the testdata, ;
- For of the testdata, ;
- For of the testdata, .
The total distance from to does not exceed .
, and each segment length is a positive integer not exceeding .
Translated by ChatGPT 5
京公网安备 11011102002149号