NOI Contest Archive

Archive / 2023 / April 2023

Magical Event

Medium · National Olympiad in Informatics Sri Lanka - April 2023

There are \(n\) magicians performing a spell in a prestigious event. Magicians must form \(m\) groups. Each magician must be included in a group and one magician can only be included in only one group. Magicians of each group must be adjacent. (In the given order of the input)

\(i^{th}\) magician has a spell power of \(p_i\). When a magician is a part of the group, their spell power becomes \(p_{i}*s\), where \(s\) is the size of their group.

The owner of this event actually don’t like this performance and conspires to reduce the total power of all magicians. Owner has the authority to divide magicians in to groups as previously stated. Find and output the minimum possible total power after forming groups.

Input Format

Output Format

Constraints

Subtask 1 - 40 pts

Subtask 2 - 20 pts

Subtask 3 - 40 pts

Sample Input 0

3 2
10 20 30

Sample Output 0

90