criyle/codenet-compile-errors huggingface dataset:
Language: C++

#include<iostream>
#include<vector>
const int INF = 1e9 +5;

int main(){
 	int n, k;
    scanf("%d %d", &n, &k);
    vector<int>h(n);
   	vector<int>dp(n, INF);
    
    for(int i=0;i<n;i++)
   	  scanf("%d", &h[i]);
    dp[0] = 0;
  
    for(int i=0;i<n;i++){
     int dist = i+k;
  	 for(int j=i;j<dist;j++){
       if(j<n)
       dp[j] = min(dp[j], dp[i]+abs(h[j]-h[i]));
     }
    }
  
    printf("%d\n",dp[n-1]);
 	return 0;
 }

Compiler output:
a.cc: In function 'int main()':
a.cc:8:5: error: 'vector' was not declared in this scope
    8 |     vector<int>h(n);
      |     ^~~~~~
a.cc:8:5: note: suggested alternatives:
In file included from /usr/include/c++/14/vector:66,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_vector.h:428:11: note:   'std::vector'
  428 |     class vector : protected _Vector_base<_Tp, _Alloc>
      |           ^~~~~~
/usr/include/c++/14/vector:93:13: note:   'std::pmr::vector'
   93 |       using vector = std::vector<_Tp, polymorphic_allocator<_Tp>>;
      |             ^~~~~~
a.cc:8:12: error: expected primary-expression before 'int'
    8 |     vector<int>h(n);
      |            ^~~
a.cc:9:16: error: expected primary-expression before 'int'
    9 |         vector<int>dp(n, INF);
      |                ^~~
a.cc:12:24: error: 'h' was not declared in this scope
   12 |           scanf("%d", &h[i]);
      |                        ^
a.cc:13:5: error: 'dp' was not declared in this scope
   13 |     dp[0] = 0;
      |     ^~
a.cc:19:37: error: 'h' was not declared in this scope
   19 |        dp[j] = min(dp[j], dp[i]+abs(h[j]-h[i]));
      |                                     ^
a.cc:19:16: error: 'min' was not declared in this scope; did you mean 'std::min'?
   19 |        dp[j] = min(dp[j], dp[i]+abs(h[j]-h[i]));
      |                ^~~
      |                std::min
In file included from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: 'std::min' declared here
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
Language: C++

#include <iostream>
using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int k;
	long int n;
	cin>>n>>k;
	int h[n];
	for(int i = 0; i < n; i++) {
		cin>>h[i];
	}
	int cost[n] = 1e9;
	cost[0] = 0;
	
	for(int i = 0; i < n; i++) {
		for(int j = 1; j <=k; j++) {
			if(i-j>=0)
		cost[i] = std::min(cost[i],cost[i-j]+abs(h[i] -h[i-j]));
	}

}
		cout<<cost[n-1]<<"\n";
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:14:23: error: array must be initialized with a brace-enclosed initializer
   14 |         int cost[n] = 1e9;
      |                       ^~~
Language: C++

#include<bits/stdc++.h>
using namespace std;

#define MAX 20000000000
#define FOR(i,m,n) for(int i = (m); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define all(v) v.begin(),v.end()


typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;

int main(){
	
	ll n,k,x,dp[MAX];
	vector<ll> v;
	cin>>n>>k;

	REP(i,n){
		cin>>x;
		v.pb(x);
	}
	dp[0]=0;
	dp[1]=abs(v[1]-v[0]);
	FOR(i,2,n){
		dp[i]=MAX;
		for(int j=i-1; j>=max(i-k,0); j--){

			if(dp[i]>dp[j]+abs(v[i]-v[j])){
				dp[i]=dp[j]+abs(v[i]-v[j]);

			}
		}
	}
	//cout<<dp[n-1]<<endl;

	
	cout<<dp[n-1]<<endl;

	return 0;
	
}

Compiler output:
a.cc: In function 'int main()':
a.cc:32:38: error: no matching function for call to 'max(ll, int)'
   32 |                 for(int j=i-1; j>=max(i-k,0); j--){
      |                                   ~~~^~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:32:38: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   32 |                 for(int j=i-1; j>=max(i-k,0); j--){
      |                                   ~~~^~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:32:38: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   32 |                 for(int j=i-1; j>=max(i-k,0); j--){
      |                                   ~~~^~~~~~~
Language: C++

#include <iostream>
#include <vector>
#include <algorithm>
const int inf=0x3f3f3f3f;
using namespace std;

int main()
{
    int n,temp;
    cin >> n>>temp;

    vector <int> arr(n+1, 0);
    for(int i = 1; i <= n; i++)
        cin >> arr[i];

    vector <int> dp(n + 1,inf);
    dp[1]=0
    for(int i = 2; i <= n; i++)
    {
        for(int k=i-1;k>=max(1,i-temp);k--)
        {
        dp[i] = min(dp[k] + abs(arr[i] - arr[k]),dp[i]);
        }
    }
    cout << dp[n];
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:17:12: error: expected ';' before 'for'
   17 |     dp[1]=0
      |            ^
      |            ;
   18 |     for(int i = 2; i <= n; i++)
      |     ~~~     
a.cc:18:20: error: 'i' was not declared in this scope
   18 |     for(int i = 2; i <= n; i++)
      |                    ^
Language: C++

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    int n,temp;
    cin >> n>>temp;

    vector <int> arr(n+1, 0);
    for(int i = 1; i <= n; i++)
        cin >> arr[i];

    vector <int> dp(n + 1,INT_MAX);
    dp[2] = abs(arr[2] - arr[1]);
    for(int i = 3; i <= n; i++)
    {
        for(int k=1;k<=temp;k++)
        {
        dp[i] = min(dp[i - k] + abs(arr[i] - arr[i - k]),dp[i]);
        }
    }
    cout << dp[n];
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:16:27: error: 'INT_MAX' was not declared in this scope
   16 |     vector <int> dp(n + 1,INT_MAX);
      |                           ^~~~~~~
a.cc:4:1: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
    3 | #include <algorithm>
  +++ |+#include <climits>
    4 |
Language: C++

#include <iostream>
#include <algorithm>

using namespace std;
const int maxn = 1e5 + 10;
const int INF = 0x3f3f3f3f;

int f[maxn];
int h[maxn];
int main()
{
	int n, k;
	scanf("%d%d", &n, &k);
	memset(f, INF, sizeof(f));
	f[0] = 0;
	for(int i = 0; i < n; i++) scanf("%d",&h[i]);
	for(int i = 0; i < n; i++)
		for(int j = 1; j <= k && i-j >= 0; j++)
				f[i] = min(f[i], f[i-j] + abs(h[i]-h[i-j]));

	// for(int i = 0; i < n; i++)
	// 	cout << f[i] << endl;
	printf("%d\n", f[n-1]);
	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:14:9: error: 'memset' was not declared in this scope
   14 |         memset(f, INF, sizeof(f));
      |         ^~~~~~
a.cc:3:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    2 | #include <algorithm>
  +++ |+#include <cstring>
    3 |
Language: C++

#コピペ 何秒かかるか
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const long long INF = 1LL << 60;

// 入力
int N;
long long h[100010];

// DP テーブル
long long dp[100100];

int main() {
    int N, K; cin >> N >> K;
    for (int i = 0; i < N; ++i) cin >> h[i];

    // 初期化 (最小化問題なので INF に初期化)
    for (int i = 0; i < 100100; ++i) dp[i] = INF;

    // 初期条件
    dp[0] = 0;

    // ループ
    for (int i = 0; i < N; ++i) {
        for (int j = 1; j <= K; ++j) {
            chmin(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
        }
    }

    // 答え
    cout << dp[N-1] << endl;
}

Compiler output:
a.cc:1:2: error: invalid preprocessing directive #\U000030b3\U000030d4\U000030da
    1 | #コピペ 何秒かかるか
      |  ^~~~~~
Language: C++

#include<bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 5;
int main()
{
	int n,k,i,j;
	cin >> n >> k;
	int h[n];
	for(i=0;i<n;i++)
	{
		cin >> h[i];
	}
	int dp[n];
	dp[0]=0;
	for(i=1;i<n;i++)
	{
		dp[i] = INT_MAX;
	}
	for(i=0;i<n;i++)
	{
		for(j=i+1;j<=i+k;j++)
		{
			if(j<n):
				dp[j] = min(dp[j], dp[i] + abs(h[i]-h[j]));
		}
	}
	cout << dp[n-1]<< endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:23:32: error: expected primary-expression before ':' token
   23 |                         if(j<n):
      |                                ^
Language: C++

import numpy as np
n, k = map(int,input().split())
a = np.array(list(map(int,input().split())))
dp_table = np.zeros(n)
for i in range(1,n):
    dp_table[i] = np.min(np.abs(a[max(0,i-k):i] - a[i]) + dp_table[max(0,i-k):i])
print(int(dp_table[-1]))


Compiler output:
a.cc:1:1: error: 'import' does not name a type
    1 | import numpy as np
      | ^~~~~~
a.cc:1:1: note: C++20 'import' only available with '-fmodules-ts'
Language: C++

#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const long long INF = 1LL << 60;

// 入力
int N;
long long h[100010];

// DP テーブル
long long dp[100100];

int main() {
    int N, K; cin >> N >> K;
    for (int i = 0; i < N; ++i) cin >> h[i];

    // 初期化 (最小化問題なので INF に初期化)
    for (int i = 0; i < 100100; ++i) dp[i] = INF;

    // 初期条件
    dp[0] = 0;

    // ループ
    for (int i = 0; i < N; ++i) {
        for (int j = 1; j <= K; ++j) {
            chmin(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
        }
    }

    // 答え
    cout << dp[N-1] << endl;

Compiler output:
a.cc: In function 'int main()':
a.cc:35:29: error: expected '}' at end of input
   35 |     cout << dp[N-1] << endl;
      |                             ^
a.cc:17:12: note: to match this '{'
   17 | int main() {
      |            ^
Language: C++

#include <bits/stdc++.h>
using namespace std;

void chmin(int &a, int b){
  if (a > b){
    a = b;
  }
}

int INF = 1000000000;
vector<int> dp(101000), h(101000, 0);

int rec(int i, int K){
  if(dp.at(i) < INF){
    return dp.at(i);
  }
  if(i == 0){
    return 0;
  }
  int res = INF;
  for(int j = 1; (j <= K, i + j <= N); j++){
    chmin(res, rec(i, K) + abs(h.at(i) - h.at(i + j)));
  }
  return dp.at(i) = res;
}

int main(){
  int N, K;
  cin >> N >> K;
  for(int i = 0; i < N; i++){
    cin >> h.at(i);
    dp.at(i) = INF;
  }
  cout << rec(N - 1, K) << endl;
}

Compiler output:
a.cc: In function 'int rec(int, int)':
a.cc:21:36: error: 'N' was not declared in this scope
   21 |   for(int j = 1; (j <= K, i + j <= N); j++){
      |                                    ^
Language: C++

#include <bits/stdc++.h>
using namespace std;

void chmin(int &a, int b){
  if (a > b){
    a = b;
  }
}

int INF = 1000000000;
vector<int> dp(101000), h(101000, 0);

int rec(int i, int K){
  if(dp.at(i) < INF){
    return dp.at(i);
  }
  if(i == 0){
    return 0;
  }
  int res = INF;
  for(int j = 1; (j <= K;i + j <= N); j++){
    chmin(res, rec(i, K) + abs(h.at(i) - h.at(i + j)));
  }
  return dp.at(i) = res;
}

int main(){
  int N, K;
  cin >> N >> K;
  for(int i = 0; i < N; i++){
    cin >> h.at(i);
    dp.at(i) = INF;
  }
  cout << rec(N - 1, K) << endl;
}

Compiler output:
a.cc: In function 'int rec(int, int)':
a.cc:21:25: error: expected ')' before ';' token
   21 |   for(int j = 1; (j <= K;i + j <= N); j++){
      |                  ~      ^
      |                         )
a.cc:21:35: error: 'N' was not declared in this scope
   21 |   for(int j = 1; (j <= K;i + j <= N); j++){
      |                                   ^
a.cc:21:39: error: 'j' was not declared in this scope
   21 |   for(int j = 1; (j <= K;i + j <= N); j++){
      |                                       ^
Language: C++

#include <bits/stdc++.h>
using namespace std;

void chmin(int &a, int b){
  if (a > b){
    a = b;
  }
}

int INF = 1000000000;
vector<int> dp(101000), h(101000, 0);

int rec(int i, int K){
  if(dp.at(i) < INF){
    return dp.at(i);
  }
  if(i == 0){
    return 0;
  }
  int res = INF;
  for(int j = 1, j <= K;i + j <= N, j++){
    chmin(res, rec(i, K) + abs(h.at(i) - h.at(i + j)));
  }
  return dp.at(i) = res;
}

int main(){
  int N, K;
  cin >> N >> K;
  for(int i = 0; i < N; i++){
    cin >> h.at(i);
    dp.at(i) = INF;
  }
  cout << rec(N - 1, K) << endl;
}

Compiler output:
a.cc: In function 'int rec(int, int)':
a.cc:21:19: error: expected ';' before '<=' token
   21 |   for(int j = 1, j <= K;i + j <= N, j++){
      |                   ^~~
      |                   ;
a.cc:21:20: error: expected primary-expression before '<=' token
   21 |   for(int j = 1, j <= K;i + j <= N, j++){
      |                    ^~
a.cc:21:34: error: 'N' was not declared in this scope
   21 |   for(int j = 1, j <= K;i + j <= N, j++){
      |                                  ^
Language: C++

#include <bits/stdc++.h>
using namespace std;

void chmin(int &a, int b){
  if (a > b){
    a = b;
  }
}

int INF = 1000000000;
vector<int> dp(101000), h(101000, 0);

int rec(int i, int K){
  if(dp.at(i) < INF){
    return dp.at(i);
  }
  if(i == 0){
    return 0;
  }
  int res = INF;
  for(int j = 1, j <= K && i + j <= N, j++){
    chmin(res, rec(i, K) + abs(h.at(i) - h.at(i + j)));
  }
  return dp.at(i) = res;
}

int main(){
  int N, K;
  cin >> N >> K;
  for(int i = 0; i < N; i++){
    cin >> h.at(i);
    dp.at(i) = INF;
  }
  cout << rec(N - 1, K) << endl;
}

Compiler output:
a.cc: In function 'int rec(int, int)':
a.cc:21:19: error: expected ';' before '<=' token
   21 |   for(int j = 1, j <= K && i + j <= N, j++){
      |                   ^~~
      |                   ;
a.cc:21:20: error: expected primary-expression before '<=' token
   21 |   for(int j = 1, j <= K && i + j <= N, j++){
      |                    ^~
a.cc:21:37: error: 'N' was not declared in this scope
   21 |   for(int j = 1, j <= K && i + j <= N, j++){
      |                                     ^
a.cc:21:43: error: expected ';' before ')' token
   21 |   for(int j = 1, j <= K && i + j <= N, j++){
      |                                           ^
      |                                           ;
Language: C++

#include <bits/stdc++.h>
using namespace std;

void chmin(int &a, int b){
  if (a > b){
    a = b;
  }
}

int INF = 1000000000;
vector<int> dp(101000), h(101000, 0);

int rec(int i, int K){
  if(dp.at(i) < INF){
    return dp.at(i);
  }
  if(i == 0){
    return 0;
  }
  int res = INF;
  for(int j = 1, j <= K || i + j <= N, j++){
    chmin(res, rec(i, K) + abs(h.at(i) - h.at(i + j)));
  }
  return dp.at(i) = res;
}

int main(){
  int N, K;
  cin >> N >> K;
  for(int i = 0; i < N; i++){
    cin >> h.at(i);
    dp.at(i) = INF;
  }
  cout << rec(N - 1, K) << endl;
}

Compiler output:
a.cc: In function 'int rec(int, int)':
a.cc:21:19: error: expected ';' before '<=' token
   21 |   for(int j = 1, j <= K || i + j <= N, j++){
      |                   ^~~
      |                   ;
a.cc:21:20: error: expected primary-expression before '<=' token
   21 |   for(int j = 1, j <= K || i + j <= N, j++){
      |                    ^~
a.cc:21:37: error: 'N' was not declared in this scope
   21 |   for(int j = 1, j <= K || i + j <= N, j++){
      |                                     ^
a.cc:21:43: error: expected ';' before ')' token
   21 |   for(int j = 1, j <= K || i + j <= N, j++){
      |                                           ^
      |                                           ;
Language: C++

#include <bits/stdc++.h>
using namespace std;

void chmin(int &a, int b){
  if (a > b){
    a = b;
  }
}

int INF = 1000000000;
vector<int> dp(101000), h(101000, 0);

int rec(int i, int K){
  if(dp.at(i) < INF){
    return dp.at(i);
  }
  if(i == 0){
    return 0;
  }
  int res = INF;
  for(int j = 1, (j <= K || i + j <= N), j++){
    chmin(res, rec(i, K) + abs(h.at(i) - h.at(i + j)));
  }
  return dp.at(i) = res;
}

int main(){
  int N, K;
  cin >> N >> K;
  for(int i = 0; i < N; i++){
    cin >> h.at(i);
    dp.at(i) = INF;
  }
  cout << rec(N - 1, K) << endl;
}

Compiler output:
a.cc: In function 'int rec(int, int)':
a.cc:21:20: error: expected ')' before '<=' token
   21 |   for(int j = 1, (j <= K || i + j <= N), j++){
      |                  ~ ^~~
      |                    )
a.cc:21:20: error: expected ';' before '<=' token
   21 |   for(int j = 1, (j <= K || i + j <= N), j++){
      |                    ^~~
      |                    ;
a.cc:21:21: error: expected primary-expression before '<=' token
   21 |   for(int j = 1, (j <= K || i + j <= N), j++){
      |                     ^~
a.cc:21:38: error: 'N' was not declared in this scope
   21 |   for(int j = 1, (j <= K || i + j <= N), j++){
      |                                      ^
a.cc:21:39: error: expected ';' before ')' token
   21 |   for(int j = 1, (j <= K || i + j <= N), j++){
      |                                       ^
      |                                       ;
a.cc:21:40: error: expected primary-expression before ',' token
   21 |   for(int j = 1, (j <= K || i + j <= N), j++){
      |                                        ^
Language: C++

#include <bits/stdc++.h>
using namespace std;

void chmin(int &a, int b){
  if (a > b){
    a = b;
  }
}

int INF = 1000000000;
vector<int> dp(101000), h(101000, 0);

int rec(int i, int K){
  if(dp.at(i) < INF){
    return dp.at(i);
  }
  if(i == 0){
    return 0;
  }
  int res = INF;
  for(int j = 1, j <= K || i + j <= N, j++){
    chmin(res, rec(i) + abs(h.at(i) - h.at(i + j)));
  }
  return dp.at(i) = res;
}

int main(){
  int N, K;
  cin >> N >> K;
  for(int i = 0; i < N; i++){
    cin >> h.at(i);
    dp.at(i) = INF;
  }
  cout << rec(N - 1, K) << endl;
}

Compiler output:
a.cc: In function 'int rec(int, int)':
a.cc:21:19: error: expected ';' before '<=' token
   21 |   for(int j = 1, j <= K || i + j <= N, j++){
      |                   ^~~
      |                   ;
a.cc:21:20: error: expected primary-expression before '<=' token
   21 |   for(int j = 1, j <= K || i + j <= N, j++){
      |                    ^~
a.cc:21:37: error: 'N' was not declared in this scope
   21 |   for(int j = 1, j <= K || i + j <= N, j++){
      |                                     ^
a.cc:21:43: error: expected ';' before ')' token
   21 |   for(int j = 1, j <= K || i + j <= N, j++){
      |                                           ^
      |                                           ;
a.cc:22:19: error: too few arguments to function 'int rec(int, int)'
   22 |     chmin(res, rec(i) + abs(h.at(i) - h.at(i + j)));
      |                ~~~^~~
a.cc:13:5: note: declared here
   13 | int rec(int i, int K){
      |     ^~~
Language: C++

#include <bits/stdc++.h>
using namespace std;

void chmin(int &a, int b){
  if (a > b){
    a = b;
  }
}

int INF = 1000000000;
vector<int> dp(101000), h(101000, 0);

int rec(int i){
  if(dp.at(i) < INF){
    return dp.at(i);
  }
  if(i == 0){
    return 0;
  }
  int res = INF;
  for(int j = 1, j <= K, j++){
    chmin(res, rec(i) + abs(h.at(i) - h.at(i + j)));
  }
  return dp.at(i) = res;
}

int main(){
  int N, K;
  cin >> N >> K;
  for(int i = 0; i < N; i++){
    cin >> h.at(i);
    dp.at(i) = INF;
  }
  cout << rec(N - 1) << endl;
}

Compiler output:
a.cc: In function 'int rec(int)':
a.cc:21:19: error: expected ';' before '<=' token
   21 |   for(int j = 1, j <= K, j++){
      |                   ^~~
      |                   ;
a.cc:21:20: error: expected primary-expression before '<=' token
   21 |   for(int j = 1, j <= K, j++){
      |                    ^~
a.cc:21:23: error: 'K' was not declared in this scope
   21 |   for(int j = 1, j <= K, j++){
      |                       ^
a.cc:21:29: error: expected ';' before ')' token
   21 |   for(int j = 1, j <= K, j++){
      |                             ^
      |                             ;
Language: C++

#include <bits/stdc++.h>
using namespace std;

void chmin(int &a, int b){
  if (a > b){
    a = b;
  }
}

int INF = 1000000000;
vector<int> dp(101000), h(101000, 0);

int rec(int i){
  if(dp.at(i) < INF){
    return dp.at(i);
  }
  if(i == 0){
    return 0;
  }
  int res = INF;
  for(int j = 1, j <= K, j++){
    chmin(res, rec(i) + abs(h.at(i) - h.at(i + j)));
  return dp.at(i) = res;
}

int main(){
  int N, K;
  cin >> N >> K;
  for(int i = 0; i < N; i++){
    cin >> h.at(i);
    dp.at(i) = INF;
  }
  cout << rec(N - 1) << endl;
}

Compiler output:
a.cc: In function 'int rec(int)':
a.cc:21:19: error: expected ';' before '<=' token
   21 |   for(int j = 1, j <= K, j++){
      |                   ^~~
      |                   ;
a.cc:21:20: error: expected primary-expression before '<=' token
   21 |   for(int j = 1, j <= K, j++){
      |                    ^~
a.cc:21:23: error: 'K' was not declared in this scope
   21 |   for(int j = 1, j <= K, j++){
      |                       ^
a.cc:21:29: error: expected ';' before ')' token
   21 |   for(int j = 1, j <= K, j++){
      |                             ^
      |                             ;
a.cc:26:9: warning: empty parentheses were disambiguated as a function declaration [-Wvexing-parse]
   26 | int main(){
      |         ^~
a.cc:26:9: note: remove parentheses to default-initialize a variable
   26 | int main(){
      |         ^~
      |         --
a.cc:26:9: note: or replace parentheses with braces to value-initialize a variable
a.cc:26:11: error: a function-definition is not allowed here before '{' token
   26 | int main(){
      |           ^
a.cc:34:2: error: expected '}' at end of input
   34 | }
      |  ^
a.cc:13:15: note: to match this '{'
   13 | int rec(int i){
      |               ^
a.cc:34:2: warning: control reaches end of non-void function [-Wreturn-type]
   34 | }
      |  ^
Language: C++

#include<bits/stdc++.h>
#include<string.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=1<<29;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};


ll dp[100001];
ll main() {

	int n,k;
	ll h[10001];

	cin>>n>>k;

	rep(i,n){
		cin>>h[i];
	}
	rep(i,100001)dp[i]=INF;

	dp[0]=0;
	for(int i=1; i<n; i++){
		for(int j=i-1; j>=i-k; j--){
			if(j>=0)dp[i]=min(dp[i],dp[j]+labs(h[i]-h[j]));
			if(j<0)break;
		}
	}
	cout<<dp[n-1]<<endl;
	return 0;
}


Compiler output:
a.cc:25:1: error: '::main' must return 'int'
   25 | ll main() {
      | ^~
Language: C++

#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,k;
  cin>>n>>k;
  int x;
  vector<int> v;
  for(int i=0;i<n;i++)
  {
    cin>>x;
    v.push_back(x);
  }
  int dp[n];
  dp[0]=v[i];
  for(int i=1;i<n;i++)
  {
    int minval=INT_MAX;
    for(int j=i-1;((j>=0)&&(j>=i-k));j--)
    {
      minval=min(minval,abs(v[i]-v[j]));
    }
    dp[i]=minval;
  }
  return dp[n-1];
}

Compiler output:
a.cc: In function 'int main()':
a.cc:15:11: error: 'i' was not declared in this scope
   15 |   dp[0]=v[i];
      |           ^
Language: C++

#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;

int main()
{
    int n;
    int i;
    int k;
    cin>>n;
    cin>>k;
    int array[n];
    int dp[n];
    for(i=0;i<n;i++)
    {
        cin>>array[i];
    }
    dp[0] = 0;
    dp[1] = abs(array[1] - array[0]); 
    int j;
    for(i=2;i<n;i++)
    {
        int prevMin = INT_MAX;
        for(j = 1; j<=k; j++)
        {
            if(i >= j)
                prevMin = min(dp[i-j] + abs(array[i] - array[i-j]), prevMin);
        }
        dp[i] = prevMin;
    }
    cout<<dp[n-1];
}

Compiler output:
a.cc: In function 'int main()':
a.cc:24:23: error: 'INT_MAX' was not declared in this scope
   24 |         int prevMin = INT_MAX;
      |                       ^~~~~~~
a.cc:4:1: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
    3 | #include<cmath>
  +++ |+#include <climits>
    4 | using namespace std;
Language: C++

#include<bits/stdc++.h>
using namespace std;
int  main()
{
  int N;
  vector<int> height(N);
  vector<int> dp(N,INT_MAX);
  
  cin >> N;
  int x;
  for(int i=0;i<N;i++)
  {
  	height.push_back(cin >> height[i]);
  }
  
  dp[0]=0;
  for(int i=0;i<N;i++)
  {
    for(int j=i+1;j<=i+k && j<N;j++)
    {
      dp[j]=min(dp[j],dp[i]+abs(height[i]-height[j]));
    }
  }
  
  cout << dp[N-1];
  
}

Compiler output:
a.cc: In function 'int main()':
a.cc:13:25: error: no matching function for call to 'std::vector<int>::push_back(std::basic_istream<char>::__istream_type&)'
   13 |         height.push_back(cin >> height[i]);
      |         ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/vector:66,
                 from /usr/include/c++/14/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:53,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_vector.h:1283:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = int; _Alloc = std::allocator<int>; value_type = int]'
 1283 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1283:35: note:   no known conversion for argument 1 from 'std::basic_istream<char>::__istream_type' {aka 'std::basic_istream<char>'} to 'const std::vector<int>::value_type&' {aka 'const int&'}
 1283 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_vector.h:1300:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(value_type&&) [with _Tp = int; _Alloc = std::allocator<int>; value_type = int]'
 1300 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1300:30: note:   no known conversion for argument 1 from 'std::basic_istream<char>::__istream_type' {aka 'std::basic_istream<char>'} to 'std::vector<int>::value_type&&' {aka 'int&&'}
 1300 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~
a.cc:19:24: error: 'k' was not declared in this scope
   19 |     for(int j=i+1;j<=i+k && j<N;j++)
      |                        ^
Language: C++

//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <unordered_map>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

//container util
//------------------------------------------
#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair

//repetition
//------------------------------------------
#define rep(i,n)  for(int i=0;i<(n);i++)


int main(){
    int n,k; cin>>n >>k;
    vi h(n);
    rep(i, n)cin>>h[i];
    
    int dp[100000];
    
    rep(i, 100000)dp[i]=INT_MAX;
    
    dp[0]=0;
    
    rep(i, n){
        for(int j=1;j<=k;j++){
            dp[i+j]=min(dp[i]+abs(h[i]-h[i+j]),dp[i+j]);
        }
    }
    
    cout<<dp[n-1]<<endl;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:57:25: error: 'INT_MAX' was not declared in this scope
   57 |     rep(i, 100000)dp[i]=INT_MAX;
      |                         ^~~~~~~
a.cc:27:1: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
   26 | #include <ctime>
  +++ |+#include <climits>
   27 |
Language: C++


	#include <bits/stdc++.h>
	#include <cstdio>
	#include <cstring>
	#include <cmath>
	#include <cstring>
	#include <chrono>
	#include <complex>
	#define endl "\n"
	#define ll long long int
	#define vi vector<int>
	#define vll vector<ll>
	#define vvi vector < vi >
	#define pii pair<int,int>
	#define pll pair<long long, long long>
	#define mod 1000000007
	#define inf 1000000000000000001;
	#define all(c) c.begin(),c.end()
	#define mp(x,y) make_pair(x,y)
	#define mem(a,val) memset(a,val,sizeof(a))
	#define eb emplace_back
	#define f first
	#define s second
	
	using namespace std;
	int main()
	{
		std::ios::sync_with_stdio(false);
		ll n,k;
		cin>>n>>k;
		ll h[n];
		for(ll i=0;i<n;i++)
			cin>>h[i];
		ll dp[n+1];
		memset(dp,inf,(n+1)*sizeof(dp[0]));
		dp[0]=0;
		dp[1]=0;
		for(ll i=2;i<=n;i++)
		{
			for(ll j=1;j<=k;j++)
			{
				if(i-j>=0)
					dp[i]=min(dp[i-j]+abs(h[i-1]-h[i-j-1]),dp[i]);
			}
		}
		cout<<dp[n];
		return 0;
	}


Compiler output:
a.cc: In function 'int main()':
a.cc:17:40: error: expected ')' before ';' token
   17 |         #define inf 1000000000000000001;
      |                                        ^
a.cc:35:27: note: in expansion of macro 'inf'
   35 |                 memset(dp,inf,(n+1)*sizeof(dp[0]));
      |                           ^~~
a.cc:35:23: note: to match this '('
   35 |                 memset(dp,inf,(n+1)*sizeof(dp[0]));
      |                       ^
a.cc:35:30: error: expected primary-expression before ',' token
   35 |                 memset(dp,inf,(n+1)*sizeof(dp[0]));
      |                              ^
Language: C++


	#include <bits/stdc++.h>
	#include <cstdio>
	#include <cstring>
	#include <cmath>
	#include <cstring>
	#include <chrono>
	#include <complex>
	#define endl "\n"
	#define ll long long int
	#define vi vector<int>
	#define vll vector<ll>
	#define vvi vector < vi >
	#define pii pair<int,int>
	#define pll pair<long long, long long>
	#define mod 1000000007
	#define inf 1000000000000000001;
	#define all(c) c.begin(),c.end()
	#define mp(x,y) make_pair(x,y)
	#define mem(a,val) memset(a,val,sizeof(a))
	#define eb emplace_back
	#define f first
	#define s second
	
	using namespace std;
	int main()
	{
		std::ios::sync_with_stdio(false);
		ll n,k;
		cin>>n>>k;
		ll h[n];
		for(ll i=0;i<n;i++)
			cin>>h[i];
		ll dp[n+1];
		memset(dp,n+1,inf);
		dp[0]=0;
		dp[1]=0;
		for(ll i=2;i<=n;i++)
		{
			for(ll j=1;j<=k;j++)
			{
				if(i-j>=0)
					dp[i]=min(dp[i-j]+abs(h[i-1]-h[i-j-1]),dp[i]);
			}
		}
		cout<<dp[n];
		return 0;
	}


Compiler output:
a.cc: In function 'int main()':
a.cc:17:40: error: expected ')' before ';' token
   17 |         #define inf 1000000000000000001;
      |                                        ^
a.cc:35:31: note: in expansion of macro 'inf'
   35 |                 memset(dp,n+1,inf);
      |                               ^~~
a.cc:35:23: note: to match this '('
   35 |                 memset(dp,n+1,inf);
      |                       ^
a.cc:35:34: error: expected primary-expression before ')' token
   35 |                 memset(dp,n+1,inf);
      |                                  ^
Language: C++


	#include <bits/stdc++.h>
	#include <cstdio>
	#include <cstring>
	#include <cmath>
	#include <cstring>
	#include <chrono>
	#include <complex>
	#define endl "\n"
	#define ll long long int
	#define vi vector<int>
	#define vll vector<ll>
	#define vvi vector < vi >
	#define pii pair<int,int>
	#define pll pair<long long, long long>
	#define mod 1000000007
	#define inf 1000000000000000001;
	#define all(c) c.begin(),c.end()
	#define mp(x,y) make_pair(x,y)
	#define mem(a,val) memset(a,val,sizeof(a))
	#define eb emplace_back
	#define f first
	#define s second
	
	using namespace std;
	int main()
	{
		std::ios::sync_with_stdio(false);
		ll n,k;
		cin>>n>>k;
		ll h[n];
		for(ll i=0;i<n;i++)
			cin>>h[i];
		dp[n+k-1]={0};
		for(ll i=k;i<n+k-1;i++)
		{
			for(ll j=1;j<=k;j++)
				dp[i]=min(dp[i-j]+abs(h[i-j-1]-h[i-1]),dp[i]);
		}
		cout<<dp[n+k-2];
		return 0;
	}


Compiler output:
a.cc: In function 'int main()':
a.cc:34:17: error: 'dp' was not declared in this scope; did you mean 'dup'?
   34 |                 dp[n+k-1]={0};
      |                 ^~
      |                 dup
Language: C++

#include <iostream>
#include<stdio.h>
#include<algorithm>
#include<bits/stdc++.h>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<string.h>
#include<cmath>
#define maxn 1000010
#define ll long long
#define inf 0x3f3f3f3f
using namespace std;

ll h[maxn];
ll dp[maxn];
ll n,k;

int main()
{
    memset(h,0,sizeof h);
    scanf("%lld%lld",&n,&k);

    for(int i=1;i<=n;i++)
    {
        dp[i]=inf;
        scanf("%lld",&h[i]);
    }
    dp[1]=0;
    dp[0]=0;
    dp[2]=abs(h[2]-h[1]);
    for(int i=2;i<=n;i++)
    {
        for(int j=i-1;j>=max(i-k,1);j--)
            dp[i]=min(dp[i],dp[j]+abs(h[i]-h[j]));
    }
    printf("%lld\n",dp[n]);
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:34:29: error: no matching function for call to 'max(long long int, int)'
   34 |         for(int j=i-1;j>=max(i-k,1);j--)
      |                          ~~~^~~~~~~
In file included from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:34:29: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   34 |         for(int j=i-1;j>=max(i-k,1);j--)
      |                          ~~~^~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:3:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:34:29: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   34 |         for(int j=i-1;j>=max(i-k,1);j--)
      |                          ~~~^~~~~~~
Language: C++

#include<iostream>
#include<cmath>
using namespace std;

int main()
{
  int n,k;
  cin>>n>>k;
  int h[n+1];
  for(int i=1;i<=n;i++)
    cin>>h[i];
  int m[n+1];
  int mi;
  m[0]=0;
  m[1]=0;
  m[2]=abs(h[2]-h[1]);
  for(int i=3;i<=n;i++)
  {   mi=INT_MAX;
    int j;
    if(n-k>=1)
        j=n-k;
    else
        j=1;
      for(j;j<i;j++)
      {
          if(m[j]+abs(h[j]-h[i])<mi)
          {
              mi=m[j]+abs(h[j]-h[i]);
              m[i]=mi;
          }
      }
  }
  cout<<m[n];
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:18:10: error: 'INT_MAX' was not declared in this scope
   18 |   {   mi=INT_MAX;
      |          ^~~~~~~
a.cc:3:1: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
    2 | #include<cmath>
  +++ |+#include <climits>
    3 | using namespace std;
Language: C++

#include <iostream>
#include <vector>
#include <algorithm> // sort
#include <map> // pair
#include <numeric> // accumulate(begin,end,初期値)
#include <string>

typedef long long ll;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<x<<endl
#define rep(i,n) for(int i = 0;i < (n);++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SUM(vec) accumulate(all(vec),0)

const ll INF = 1e9+7;

// 各桁の和
template<typename T>T digit(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;}
template<typename T>T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);}
template<typename T>T lcm(T a, T b){T g = gcd(a,b);return a/g*b;}
template<typename T>T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;}

int main() {
  int n,k;cin>>n>>k;
  vector<ll> h(n);rep(i,n)cin>>h[i];
  vector<l> dp(n+100,1000000);
  dp[0] = 0;
  for(int i = 0;i < n;++i){
    for(int j = 1;j <= k;++j){
      	dp[i+j] = min(dp[i+j], dp[i]+abs(h[i]-h[i + j]));
    }
  }
  
  print(dp[n-1]);
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:33:10: error: 'l' was not declared in this scope
   33 |   vector<l> dp(n+100,1000000);
      |          ^
a.cc:33:11: error: template argument 1 is invalid
   33 |   vector<l> dp(n+100,1000000);
      |           ^
a.cc:33:11: error: template argument 2 is invalid
a.cc:33:29: error: expression list treated as compound expression in initializer [-fpermissive]
   33 |   vector<l> dp(n+100,1000000);
      |                             ^
a.cc:34:5: error: invalid types 'int[int]' for array subscript
   34 |   dp[0] = 0;
      |     ^
a.cc:37:11: error: invalid types 'int[int]' for array subscript
   37 |         dp[i+j] = min(dp[i+j], dp[i]+abs(h[i]-h[i + j]));
      |           ^
a.cc:37:25: error: invalid types 'int[int]' for array subscript
   37 |         dp[i+j] = min(dp[i+j], dp[i]+abs(h[i]-h[i + j]));
      |                         ^
a.cc:37:34: error: invalid types 'int[int]' for array subscript
   37 |         dp[i+j] = min(dp[i+j], dp[i]+abs(h[i]-h[i + j]));
      |                                  ^
a.cc:41:11: error: invalid types 'int[int]' for array subscript
   41 |   print(dp[n-1]);
      |           ^
a.cc:14:24: note: in definition of macro 'print'
   14 | #define print(x) cout<<x<<endl
      |                        ^
Language: C++

// frog2

#include <iostream>
#include <vector>
#define ll long long
using namespace std;

int n, k;
ll arr[1000005];
ll dp[1000005];

ll cost(int x)
{
    if (dp[x] != -1)
        return dp[x];
    if (x == n)
        return 0;
    if (x == n - 1)
        return abs(arr[x] - arr[x + 1]);

    long long minCost = INT_MAX;
    for (int i = 1; i <= k && x + i <= n; i++)
    {
        dp[x + i] = cost(x + i);
        minCost = min(minCost, abs(arr[x + i] - arr[x]) + dp[x + i]);
    }
    dp[x] = minCost;
    return dp[x];
}

int main()
{
    cin >> n >> k;
    for (int i = 1; i <= n; i++)
    {
        cin >> arr[i];
    }
    for (int i = 0; i < 1000005; i++)
    {
        dp[i] = -1;
    }
    cout << cost(1);
}

Compiler output:
a.cc: In function 'long long int cost(int)':
a.cc:21:25: error: 'INT_MAX' was not declared in this scope
   21 |     long long minCost = INT_MAX;
      |                         ^~~~~~~
a.cc:5:1: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
    4 | #include <vector>
  +++ |+#include <climits>
    5 | #define ll long long
Language: C++

n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [0] * n
dp[0] = 0
dp[1] = abs(h[1] - h[0])
for i in range(2, n):
    dp[i] = dp[i - 1] + abs(h[i] - h[i - 1])
    for j in range(2, min(i + 1, k + 1)):
        dp[i] = min(dp[i - j] + abs(h[i] - h[i - j]), dp[i])
print(dp[n - 1])

Compiler output:
a.cc:1:1: error: 'n' does not name a type
    1 | n, k = map(int, input().split())
      | ^
Language: C++

def main():
    n, k = map(int, input().split())
    h = list(map(int, input().split()))
    dp = [0] * n
    dp[0] = 0
    dp[1] = abs(h[1] - h[0])
    for i in range(2, n):
        dp[i] = dp[i - 1] + abs(h[i] - h[i - 1])
        for j in range(2, min(i + 1, k + 1)):
            dp[i] = min(dp[i - j] + abs(h[i] - h[i - j]), dp[i])
    print(dp[n - 1])


if __name__ == '__main__':
    main()


Compiler output:
a.cc:14:16: warning: multi-character literal with 8 characters exceeds 'int' size of 4 bytes
   14 | if __name__ == '__main__':
      |                ^~~~~~~~~~
a.cc:1:1: error: 'def' does not name a type
    1 | def main():
      | ^~~
Language: C++

#include <bits/stdc++.h>
using namespace std;
int main(){
 int n, k, i;
 cin>>n>>k;
 long long arr[100001];
 long long dp[100001];
 for(i=0;i<n;i++)
   cin>>arr[i];
 for(i=0;i<n;i++)
   dp[i]=INT_MAX;
 dp[0]=0;
 dp[1]=abs(arr[1]-arr[0]);
 for(i=2;i<n;i++)
 {
   //dp[i]=dp[i-1]+abs(arr[i]-arr[i-1]);
   for(j=i-1;i-j<=k && j>=0;j--)
   {
     dp[i]=min(dp[i], dp[j]+abs(arr[i]-arr[j]));
   }
 }
 cout<<dp[n-1]<<endl;
 return 0;
}
  

Compiler output:
a.cc: In function 'int main()':
a.cc:17:8: error: 'j' was not declared in this scope
   17 |    for(j=i-1;i-j<=k && j>=0;j--)
      |        ^
Language: C++

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); i++)
#define ct(string) cout << string << endl

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> cost(n);
    vector<int> dp(n, INT_MAX);
    rep(i,n) cin >> cost.at(i);
    dp.at(0) = 0;
    rep(i,n) {
        rep(j,k) {
            if (i < j+1) break;
            dp.at(i) = min(dp.at(i-j-1)+abs(cost.at(i)-cost.at(i-j-1)), dp.at(i));
        }
    }
    ct(dp.at(n-1));
}

Compiler output:
a.cc: In function 'int main()':
a.cc:12:23: error: 'INT_MAX' was not declared in this scope
   12 |     vector<int> dp(n, INT_MAX);
      |                       ^~~~~~~
a.cc:4:1: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
    3 | #include <algorithm>
  +++ |+#include <climits>
    4 | using namespace std;
Language: C++

#include<bits/stdc++.h>

#define ll long long int
#define hell 998244353
#define vi vector <ll>
#define pb push_back
#define pii pair<ll,ll>
#define vii vector <pii>
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define sep(i,a,b)  for(ll i=a-1;i>=b;i--)
#define inf (ll)(1e16)

using namespace std;

void solve(){
    ll n,k;
    cin>>n>>k;
    vi a(n),dp(n,inf);
    rep(i,0,n)
        cin>>a[i];
    dp[0]=0;
    rep(i,1,n)
    {
        sep(j,i,max(ll(0),i-k))
            dp[i]=min(dp[i],dp[j]+abs(a[i]-a[j]));
    }
    cout<<dp.back();
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll t=1;
    //cin>>t;
    while(t--)
        solve();
    return 0;
}


Compiler output:
a.cc: In function 'void solve()':
a.cc:3:12: error: expected primary-expression before 'long'
    3 | #define ll long long int
      |            ^~~~
a.cc:10:37: note: in definition of macro 'sep'
   10 | #define sep(i,a,b)  for(ll i=a-1;i>=b;i--)
      |                                     ^
a.cc:24:21: note: in expansion of macro 'll'
   24 |         sep(j,i,max(ll(0),i-k))
      |                     ^~
Language: C++

#include<iostream>
#include<cmath>
using namespace std;
int main()
{
  int n,k;cin>>n>>k;int h[n];
  for (int i=0;i<n;i++)cin>>h[i];int ans[n];ans[0]=0;ans[1]=abs(h[1]-h[0]);
  for (int i=2;i<n;i++)
  {
    ans[i]=ans[i-1]+abs(h[i]-h[i-1]);
    for (int j=i-2;j>=max(0,i-k);j--)
    {
      ans[i]=min(a[i],ans[j]+abs(h[i]-h[j]));}
  }
  cout<<ans[n-1];return 0;}
  
  

Compiler output:
a.cc: In function 'int main()':
a.cc:13:18: error: 'a' was not declared in this scope
   13 |       ans[i]=min(a[i],ans[j]+abs(h[i]-h[j]));}
      |                  ^
Language: C++

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define faster ios_base::sync_with_stdio(0);
#define faster_tie cin.tie(0);
#define fr(i,a,b) for(int i=a;i<=b;i++)
#define NL cout<<'\n'

ll n,k,x;
vector<ll>height;
ll sol[110000]={0};

ll solve(ll x)
{
    if(x==1)
    {
        sol[x]=0;
        return 0;
    }
    if(sol[x]!=0)return sol[x];
    ll a=INT_MAX;

    for(ll i=x-1;i>max(1,x-1-k);i--)
    {
        if(i==0)break;
        a=min(a,solve(i)+abs(height[i]-height[x]));
    }
    sol[x]=a;
    return a;

}


int main()
{
    cin>>n>>k;
    height.push_back(-1);
    for(int i=0;i<n;i++)
    {
        cin>>x;
        height.push_back(x);
    }

    ll ans=solve(n);
    cout<<ans;



    return 0;
}


Compiler output:
a.cc: In function 'll solve(ll)':
a.cc:23:23: error: no matching function for call to 'max(int, ll)'
   23 |     for(ll i=x-1;i>max(1,x-1-k);i--)
      |                    ~~~^~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:23:23: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
   23 |     for(ll i=x-1;i>max(1,x-1-k);i--)
      |                    ~~~^~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:23:23: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   23 |     for(ll i=x-1;i>max(1,x-1-k);i--)
      |                    ~~~^~~~~~~~~