For this Question: Given a sorted array of size N and an integer K. You have to divide the given array into K non-empty subarrays such that each array index is in exactly one of the subarrays.
Divide the array such that the following value is minimized:
summation (max(i) - min(i)) for i from 1 to K
where max(i) is the maximum value in the subarray i.
and min(i) is the minimum value in the subarray i.
For example, if we have an array [1, 2, 3, 4, 5, 6] and we split it as [1, 2] [3, 4, 5] [6] then the value we get will be (2 - 1) + (5 - 3) + (6 - 6) = 3.The first line of the input contains two integers N and K.
The next line contain N integers.

Constraints
1 <= K <= N <= 100000
1 <= Arr[i] <= 10^9Print the minimum value you can obtain after dividing the array.Sample Input
6 3
4 8 15 16 23 42

Sample Output
12

Explanation: we split the array as [4, 8, 15, 16], [23], [42]

Sample Input:-
6 3
1 2 3 4 5 6

Sample Output:-
3

Sample Input:-
5 5
1 2 3 4 5

Sample Output:-
0, I have written this Solution Code: #pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc  __builtin_popcountll
#define m_p make_pair
#define infi 1e18+1
#define eps 0.000000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
    return uniform_int_distribution<T>()(rng);
}
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

template<class T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
 
//////////////
auto clk=clock();
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define sz(x) ((long long)x.size())
#define int long long  
#define f80 __float128
#define pii pair<int,int>
/////////////

const int N = (3e5);

int n, k;
int a[N];

signed main(){
	fastio;
	#ifdef ANIKET_GOYAL
		freopen("inputf.in","r",stdin);
		freopen("outputf.in","w",stdout);
	#endif
	cin >> n >> k;
	for(int i = 0; i < n; ++i){
		cin>>a[i];
	}
	vector <int> v;
	for(int i = 1; i < n; ++i) v.push_back(a[i - 1] - a[i]);
	
	sort(v.begin(), v.end());
	
	int res = a[n - 1] - a[0];
	for(int i = 0; i < k - 1; ++i) res += v[i];
	
	cout << res;
 	return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not?