QOJ.ac

QOJ

حد الوقت: 1 s حد الذاكرة: 256 MB مجموع النقاط: 100

#4105. Journey

الإحصائيات

Pine has begun a journey from location S to location T. The road from S to T can be divided into $n$ segments, with rest stops located at the boundaries between adjacent segments. Pine plans to reach T in $m$ days. Except for the $m$-th day, Pine must spend every night at a rest stop. Therefore, each segment of the road must be completed within a single day. Pine wants the distance traveled each day to be as similar as possible, so he hopes to minimize the variance of the distances traveled each day. Help Pine find the minimum possible variance. Let the variance be $v$. It can be proven that $v \cdot m^2$ is an integer. To avoid precision errors, output the value of $v \cdot m^2$.

Input

The first line contains two integers $n$ and $m$. The second line contains $n$ integers, representing the lengths of the $n$ road segments.

Output

A single integer, the value of the minimum variance multiplied by $m^2$.

Examples

Input 1

5 2
1 2 5 8 6

Output 1

36

Constraints

For 30% of the data, $1 \le n \le 10$. For 60% of the data, $1 \le n \le 100$. For 100% of the data, $1 \le n \le 3000$. It is guaranteed that the total distance from S to T does not exceed $30000$.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.