#P4677. 山区建小学
山区建小学
Description
The government has built a single road in a mountainous area that passes through each of the villages exactly once, with no cycles or intersections. Any two villages can communicate only along this road. The distance between any two adjacent villages is (each is a positive integer), where . To improve education in the area, the government will choose out of the villages to build primary schools. Given , , and the distances between all adjacent villages, decide in which villages to build the primary schools so that the sum of distances from all villages to their nearest primary school is minimized, and compute this minimum value.
Input Format
The first line contains and , separated by a space. The second line contains integers, in order from one end to the other, representing the distances between adjacent villages, separated by spaces.
For example
10 3
2 4 6 5 2 4 3 1 3
means building primary schools among villages. The distance between village and village is , between village and village is , between village and village is , ..., and between village and village is .
Output Format
Output the minimal sum of distances from all villages to their nearest primary school.
10 2
3 1 3 1 1 1 1 1 3
18
Hint
, .
Translated by ChatGPT 5
京公网安备 11011102002149号