#P17319. [ICPC 2018 Nanjing R] Tournament

    ID: 19661 远端评测题 3000ms 512MiB 尝试: 0 已通过: 0 显示难度NOI/NOI+/CTS 上传者: 标签>2018动态规划优化凸完全单调性(wqs 二分)四边形不等式ICPC南京决策单调性

[ICPC 2018 Nanjing R] Tournament

Problem Description

There are NN villagers (including the village chief) living in Number Village. Interestingly, all of their houses lie on a straight line. The house of the ii-th villager (0≤i<N0\leq i<N) lies exactly aia_i kilometers to the east of the village chief's house. (For simplicity, the 00-th villager is the village chief, so a0=0a_0=0.)

Recently, a tournament is going to be held in Number Village, in which everyone in the village will participate.

For the convenience of villagers, the organizer plans to build KK stadiums. The stadium can be built anywhere in the village, even at the same place as any villager's house.

However, the organizer wants the traffic cost to be minimized. The traffic cost is defined by ∑i=0N−1min⁡j=0K−1D(ai,sj)\sum_{i=0}^{N-1} \min_{j=0}^{K-1} D(a_i, s_j), where D(ai,sj)D(a_i, s_j) is the distance between the ii-th villager's house and the jj-th stadium.

Your task is to calculate the minimal traffic cost (rounded down to the nearest integer), given N,KN, K and aia_i.

Input Format

The first line contains two positive integers N,KN,K (K≤N≤3×105K\leq N\leq 3\times 10^ 5).

The second line contains NN non-negative integers a0,a1,⋯ ,aN−1a_0,a_1,\cdots,a_{N-1} (0=a0<a1<⋯<aN−1≤1090=a_0<a_1<\cdots<a_{N-1}\leq 10^ 9).

Output Format

Print a single integer —\text{---} the minimal traffic cost rounded down to the nearest integer.

5 2
0 4 7 9 10
7
9 3
0 1 10 11 20 21 22 30 32
23