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: import java.io.*;
import java.util.*;



class Main {
	public static void main (String[] args) throws IOException{
        BufferedReader br = new BufferedReader( new InputStreamReader(System.in));
        String input[] = br.readLine().split(" ");
        int n = Integer.parseInt(input[0]);
        int k = Integer.parseInt(input[1]);
        String[] stringArr = br.readLine().split(" ");
        int[] arr = new int[n];
        for(int i=0; i<n; i++){
            arr[i] = Integer.parseInt(stringArr[i]);
        }

        int[] diff = new int[n-1];
        int j=0;
        for(int i=1; i<n; i++){
            diff[j] = arr[i]-arr[i-1];

            j++;
        }

        Arrays.sort(diff);

        int sum = 0;
        for(j = 0; j <= n-k-1; j++) {
            sum += diff[j];
        }
        System.out.print(sum);
	}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not?