LearnPy Hub
← Arena
AdvancedRating 1800

Cheapest Way to Cut a Stick

A stick of length L must be cut at the given positions. Each cut costs the length of the piece being cut. Choose the order of cuts to minimise the total cost and print it.

Input

L and k (≤ 100); then k distinct cut positions.

Output

One integer.

Sample 1

Input
7 4
1 3 4 5
Output
16

Sample 2

Input
9 5
5 6 1 4 2
Output
22
solution.py
Output appears here
Cheapest Way to Cut a Stick · Python Arena problem · LearnPy Hub