Language: C++

import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
      	int k = in.nextInt();

		int[] a = new int[n];
		int[] h = new int[n];
		for(int i=0;i<n;i++) {
			h[i] = in.nextInt();
		}
		for(int i=0;i<n;i++) {
			a[i] = Integer.MAX_VALUE;
		}
		a[0] = 0;
		for(int i=0;i<n;i++) {
          for(int j = 0; j<k; j++){            
			if(i<n-k)a[i+k] = Math.min(a[i+k], a[i]+Math.abs(h[i]-h[i+k]));
			
          }
		}
		System.out.println(a[n-1]);
	}
}


Compiler output:
a.cc:1:1: error: 'import' does not name a type
    1 | import java.util.*;
      | ^~~~~~
a.cc:1:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:4:15: error: expected ':' before 'static'
    4 |         public static void main(String[] args) {
      |               ^~~~~~~
      |               :
a.cc:4:33: error: 'String' has not been declared
    4 |         public static void main(String[] args) {
      |                                 ^~~~~~
a.cc:4:42: error: expected ',' or '...' before 'args'
    4 |         public static void main(String[] args) {
      |                                          ^~~~
a.cc:26:2: error: expected ';' after class definition
   26 | }
      |  ^
      |  ;
a.cc: In static member function 'static void Main::main(int*)':
a.cc:5:17: error: 'Scanner' was not declared in this scope
    5 |                 Scanner in = new Scanner(System.in);
      |                 ^~~~~~~
a.cc:6:25: error: 'in' was not declared in this scope; did you mean 'int'?
    6 |                 int n = in.nextInt();
      |                         ^~
      |                         int
a.cc:9:20: error: structured binding declaration cannot have type 'int'
    9 |                 int[] a = new int[n];
      |                    ^~
a.cc:9:20: note: type must be cv-qualified 'auto' or reference to cv-qualified 'auto'
a.cc:9:20: error: empty structured binding declaration
a.cc:9:23: error: expected initializer before 'a'
    9 |                 int[] a = new int[n];
      |                       ^
a.cc:10:20: error: structured binding declaration cannot have type 'int'
   10 |                 int[] h = new int[n];
      |                    ^~
a.cc:10:20: note: type must be cv-qualified 'auto' or reference to cv-qualified 'auto'
a.cc:10:20: error: empty structured binding declaration
a.cc:10:23: error: expected initializer before 'h'
   10 |                 int[] h = new int[n];
      |                       ^
a.cc:12:25: error: 'h' was not declared in this scope
   12 |                         h[i] = in.nextInt();
      |                         ^
a.cc:15:25: error: 'a' was not declared in this scope
   15 |                         a[i] = Integer.MAX_VALUE;
      |                         ^
a.cc:15:32: error: 'Integer' was not declared in this scope
   15 |                         a[i] = Integer.MAX_VALUE;
      |                                ^~~~~~~
a.cc:17:17: error: 'a' was not declared in this scope
   17 |                 a[0] = 0;
      |                 ^
a.cc:20:43: error: 'Math' was not declared in this scope
   20 |                         if(i<n-k)a[i+k] = Math.min(a[i+k], a[i]+Math.abs(h[i]-h[i+k]));
      |                                           ^~~~
a.cc:20:74: error: 'h' was not declared in this scope
   20 |                         if(i<n-k)a[i+k] = Math.min(a[i+k], a[i]+Math.abs(h[i]-h[i+k]));
      |                                                                          ^
a.cc:24:17: error: 'System' was not declared in this scope
   24 |                 System.out.println(a[n-1]);
      |                 ^~~~~~