Language: C++

 class frog2 {
		public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		
		sc.nextLine();
		int[] heights = new int[n];
		for(int i = 0; i < n; i++) {
			heights[i] = sc.nextInt();
		}
		
		int[] dp = new int[n]; //min number of cost before reaching i
		for (int i = 0; i < dp.length; i++) {
			dp[i] = Integer.MAX_VALUE;
		}
		dp[0] = 0;
		for (int i = 0; i < n; i++) {
			for(int j = i+1; j <= i+k; j++) {
				if(j < n) {
					dp[j] = Math.min(dp[j], dp[i] + Math.abs(heights[i] - heights[j]));
				}
			}
			
		}
		System.out.println(dp[n-1]);
	}
	 
}


Compiler output:
a.cc:2:23: error: expected ':' before 'static'
    2 |                 public static void main(String[] args) {
      |                       ^~~~~~~
      |                       :
a.cc:2:41: error: 'String' has not been declared
    2 |                 public static void main(String[] args) {
      |                                         ^~~~~~
a.cc:2:50: error: expected ',' or '...' before 'args'
    2 |                 public static void main(String[] args) {
      |                                                  ^~~~
a.cc:29:2: error: expected ';' after class definition
   29 | }
      |  ^
      |  ;
a.cc: In static member function 'static void frog2::main(int*)':
a.cc:3:17: error: 'Scanner' was not declared in this scope
    3 |                 Scanner sc = new Scanner(System.in);
      |                 ^~~~~~~
a.cc:4:25: error: 'sc' was not declared in this scope
    4 |                 int n = sc.nextInt();
      |                         ^~
a.cc:8:20: error: structured binding declaration cannot have type 'int'
    8 |                 int[] heights = new int[n];
      |                    ^~
a.cc:8:20: note: type must be cv-qualified 'auto' or reference to cv-qualified 'auto'
a.cc:8:20: error: empty structured binding declaration
a.cc:8:23: error: expected initializer before 'heights'
    8 |                 int[] heights = new int[n];
      |                       ^~~~~~~
a.cc:10:25: error: 'heights' was not declared in this scope
   10 |                         heights[i] = sc.nextInt();
      |                         ^~~~~~~
a.cc:13:20: error: structured binding declaration cannot have type 'int'
   13 |                 int[] dp = new int[n]; //min number of cost before reaching i
      |                    ^~
a.cc:13:20: note: type must be cv-qualified 'auto' or reference to cv-qualified 'auto'
a.cc:13:20: error: empty structured binding declaration
a.cc:13:23: error: expected initializer before 'dp'
   13 |                 int[] dp = new int[n]; //min number of cost before reaching i
      |                       ^~
a.cc:14:37: error: 'dp' was not declared in this scope
   14 |                 for (int i = 0; i < dp.length; i++) {
      |                                     ^~
a.cc:15:33: error: 'Integer' was not declared in this scope
   15 |                         dp[i] = Integer.MAX_VALUE;
      |                                 ^~~~~~~
a.cc:17:17: error: 'dp' was not declared in this scope
   17 |                 dp[0] = 0;
      |                 ^~
a.cc:21:49: error: 'Math' was not declared in this scope
   21 |                                         dp[j] = Math.min(dp[j], dp[i] + Math.abs(heights[i] - heights[j]));
      |                                                 ^~~~
a.cc:21:82: error: 'heights' was not declared in this scope
   21 |                                         dp[j] = Math.min(dp[j], dp[i] + Math.abs(heights[i] - heights[j]));
      |                                                                                  ^~~~~~~
a.cc:26:17: error: 'System' was not declared in this scope
   26 |                 System.out.println(dp[n-1]);
      |                 ^~~~~~