Language: Java

#include <iostream>
#include <math.h>

using namespace std;

int menorCusto = 2000000000;
int dMax = 0;

void geraComb(int posAtual, int qtdCand, int passoMax, int *n, bool vBool[], int v[], int *dMax);
void verifSolucao(bool vBool[], int v[], int k, int *n);


int main(){
	int num;
	int n;
	int k;
	int high;
	
	//cin >> n >> k;
	scanf("%d",&n);
	scanf("%d",&k);
	
	int v[n];
	//vector <int> v;
	bool vBool[n];
	
	for(int i = 0; i < n; i++){
		//cin >> v[i];
		scanf("%d",&v[i]);
		//cin >> num;
		//v.push_back(num);
		vBool[i] = false;
	}
	
	geraComb(0, n, k, &n, vBool, v, &dMax);
	
	//cout << menorCusto << endl;
	printf("%d", menorCusto);
}

void geraComb(int posAtual, int qtdCand, int passoMax, int *n, bool vBool[], int v[], int *dM){
	//cout << *dMax << endl;
	if(*dM >= passoMax){
		//*dM -= 1;
		return;	
	}
	if(posAtual == *n /*- 1*/ && vBool[0] && vBool[*n - 1]) verifSolucao(vBool, v, passoMax, n);
	else{
		for(int i = 0; i < *n; i++){
			int aux = 0;
			if(posAtual + i + 1 <= *n){
				//cout << "\nposAtual + 1 = " << posAtual + 1 << " qtdCand - 1 = " << qtdCand - 1 << " passoMax = " << passoMax << " n = " << *n;
				vBool[posAtual /*+ i*/] = true;
				aux = *dM;
				*dM = 0; //cout << "T" << *dM << endl;
				geraComb(posAtual + 1, qtdCand - 1, passoMax, n, vBool, v, dM);
				if(vBool[posAtual]) *dM = aux;
				if(!vBool[0] || posAtual == (*n - 1)) return;
				vBool[posAtual /*+ i*/] = false;
				*dM += 1; //cout << "F" << *dM << endl;
				geraComb(posAtual + 1, qtdCand - 1, passoMax, n, vBool, v, dM);
				//if(*dM > 0) *dM -= 1;
				/*if(!vBool[0]) */return;
			}
		}
	}
	return;
}

void verifSolucao(bool vBool[], int v[], int k, int *n){
	int pedraAnt = 0;
	int custo = 0;
	
	/*for(int i = 0; i < *n; i++)
		cout << vBool[i];*/

	for(int i = 0; i < *n; i++){
		if (vBool[i] && vBool[*n - 1] && i > 0){
			custo += fabs(v[i] - v[pedraAnt]);
			//cout << "\npedraAnt = "<< pedraAnt << " pedraAtual = " << i << " custo += (v[i] - v[pedraAnt]) = " << custo - fabs(v[i] - v[pedraAnt]) << " += fabs(" << v[i] << " - " << v[pedraAnt] << ")";
			pedraAnt = i;
		}
	}
	
	if(custo < menorCusto) menorCusto = custo;
	
		//cout << menorCusto << endl;
	//}
	
	return;
}

Compiler output:
Main.java:1: error: illegal character: '#'
#include <iostream>
^
Main.java:2: error: illegal character: '#'
#include <math.h>
^
Main.java:6: error: unnamed classes are a preview feature and are disabled by default.
int menorCusto = 2000000000;
^
  (use --enable-preview to enable unnamed classes)
Main.java:9: error: <identifier> expected
void geraComb(int posAtual, int qtdCand, int passoMax, int *n, bool vBool[], int v[], int *dMax);
                                                          ^
Main.java:9: error: class, interface, enum, or record expected
void geraComb(int posAtual, int qtdCand, int passoMax, int *n, bool vBool[], int v[], int *dMax);
                                                                             ^
Main.java:10: error: <identifier> expected
void verifSolucao(bool vBool[], int v[], int k, int *n);
                                                   ^
Main.java:23: error: not a statement
	int v[n];
	      ^
Main.java:25: error: not a statement
	bool vBool[n];
	           ^
Main.java:20: error: illegal start of expression
	scanf("%d",&n);
	           ^
Main.java:21: error: illegal start of expression
	scanf("%d",&k);
	           ^
Main.java:23: error: ';' expected
	int v[n];
	       ^
Main.java:25: error: ';' expected
	bool vBool[n];
	            ^
Main.java:29: error: illegal start of expression
		scanf("%d",&v[i]);
		           ^
Main.java:35: error: illegal start of expression
	geraComb(0, n, k, &n, vBool, v, &dMax);
	                  ^
Main.java:35: error: illegal start of expression
	geraComb(0, n, k, &n, vBool, v, &dMax);
	                                ^
Main.java:41: error: <identifier> expected
void geraComb(int posAtual, int qtdCand, int passoMax, int *n, bool vBool[], int v[], int *dM){
                                                          ^
Main.java:41: error: class, interface, enum, or record expected
void geraComb(int posAtual, int qtdCand, int passoMax, int *n, bool vBool[], int v[], int *dM){
                                                                             ^
Main.java:46: error: class, interface, enum, or record expected
	}
	^
Main.java:48: error: class, interface, enum, or record expected
	else{
	^
Main.java:49: error: class, interface, enum, or record expected
		for(int i = 0; i < *n; i++){
		               ^
Main.java:49: error: class, interface, enum, or record expected
		for(int i = 0; i < *n; i++){
		                       ^
Main.java:51: error: class, interface, enum, or record expected
			if(posAtual + i + 1 <= *n){
			^
Main.java:54: error: class, interface, enum, or record expected
				aux = *dM;
				^
Main.java:55: error: class, interface, enum, or record expected
				*dM = 0; //cout << "T" << *dM << endl;
				^
Main.java:56: error: class, interface, enum, or record expected
				geraComb(posAtual + 1, qtdCand - 1, passoMax, n, vBool, v, dM);
				^
Main.java:57: error: class, interface, enum, or record expected
				if(vBool[posAtual]) *dM = aux;
				^
Main.java:58: error: class, interface, enum, or record expected
				if(!vBool[0] || posAtual == (*n - 1)) return;
				^
Main.java:59: error: class, interface, enum, or record expected
				vBool[posAtual /*+ i*/] = false;
				^
Main.java:60: error: class, interface, enum, or record expected
				*dM += 1; //cout << "F" << *dM << endl;
				^
Main.java:61: error: class, interface, enum, or record expected
				geraComb(posAtual + 1, qtdCand - 1, passoMax, n, vBool, v, dM);
				^
Main.java:63: error: class, interface, enum, or record expected
				/*if(!vBool[0]) */return;
				                  ^
Main.java:64: error: class, interface, enum, or record expected
			}
			^
Main.java:68: error: class, interface, enum, or record expected
}
^
Main.java:77: error: class, interface, enum, or record expected
	for(int i = 0; i < *n; i++){
	^
Main.java:77: error: class, interface, enum, or record expected
	for(int i = 0; i < *n; i++){
	               ^
Main.java:77: error: class, interface, enum, or record expected
	for(int i = 0; i < *n; i++){
	                       ^
Main.java:81: error: class, interface, enum, or record expected
			pedraAnt = i;
			^
Main.java:82: error: class, interface, enum, or record expected
		}
		^
Main.java:90: error: class, interface, enum, or record expected
	return;
	^
Main.java:91: error: class, interface, enum, or record expected
}
^
40 errors