CF1197C
Meaning of the questions:
Incrementing a number of columns, it is divided into k sections, a method to find such segments, i.e. each segment minimum and maximum value minus minimum
solution:
Into k sections, i.e. to increase the k-1 partition, which partition the k-1, can be separated from some of the largest difference, that last a minimum difference maximum period after each separation and the smallest
CODE:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
#define LL long long
const int N = 3e5 + 100;
int n,a[N],k;
vector<int> G;
int main() {
scanf("%d%d",&n,&k);
for(int i = 1 ; i <= n ; ++i)
scanf("%d",&a[i]);
for(int i = 2 ; i <= n ; ++i)
G.push_back(a[i - 1] - a[i]);
sort(G.begin(), G.end());
int ans = a[n] - a[1];
for(int i = 0 ; i < k - 1 ; ++i) ans += G[i];
printf("%d",ans);
//system("pause");
return 0;
}