#P4072. [SDOI2016] 征途

    ID: 2979 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2016各省省选单调队列山东O2优化斜率优化前缀和凸包

[SDOI2016] 征途

Description

Pine starts a journey from SS to TT.

The road from SS to TT can be divided into nn segments, and there is a rest station at the boundary point between each pair of adjacent segments.

Pine plans to reach TT in mm days. Except for day mm, 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 vv. It can be proven that v×m2v \times m^2 is an integer. To avoid precision errors, output v×m2v \times m^2.

Input Format

The first line contains two integers n,mn, m.

The second line contains nn integers, representing the lengths of the nn segments.

Output Format

Output a single integer: the minimum variance multiplied by m2m^2.

5 2
1 2 5 8 6
36

Hint

  • Constraints and Conventions
    • For 30%30\% of the testdata, 1n101 \le n \le 10;
    • For 60%60\% of the testdata, 1n1001 \le n \le 100;
    • For 100%100\% of the testdata, 1n30001 \le n \le 3000.

The total distance from SS to TT does not exceed 3×1043 \times 10^4.

2mn2 \le m \le n, and each segment length is a positive integer not exceeding 3×1043 \times 10^4.

Translated by ChatGPT 5