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

#include <stdio.h>

int main (void){
  int N,K,i,k,dif,DIf,tmp,min=10000;
  int h[1000000000];
  
  scanf("%d %d",&N,&K);
  for(i=1;i<=N;i++){
    scanf("%d",&h[i]);
  }
  for(i=1;i<=N;i++){
    for(k=i;k<=N;k++){
      if(h[i]<h[k]){
        tmp=h[i];
        h[i]=h[k];
        h[k]=tmp;
      }
    }
  }
  
  dif=N-K+1;
  for(i=1;i<=dif;i++){
    DIF=h[i+K-1]-h[i];
    if( DIF<min ) min=DIF;
  }
  
  printf("%d\n",min);
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:23:5: error: 'DIF' was not declared in this scope; did you mean 'DIf'?
   23 |     DIF=h[i+K-1]-h[i];
      |     ^~~
      |     DIf
Language: C++

#include <stdio.h>

int main (void){
  int N,K,i,k,dif,DIF,min=10000;
  int h[1000000000]
  
  scanf("%d %d",&N,&K);
  for(i=1;i<=N;i++){
    scanf("%d",&h[i]);
  }
  for(i=1;i<=N;i++){
    for(k=i;k<N;k++){
      if(h[i]<h[k]){
        tmp=h[i];
        h[i]=h[k];
        h[k]=tmp;
      }
    }
  }
  dif=N-K;
  for(i=1;i<=dif;i++){
    DIF=h[i+K]-h[i];
    if( DIF<min ) min=DIF;
  }
  
  printf("%d\n",min);
  
  reutrn 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:7:3: error: expected initializer before 'scanf'
    7 |   scanf("%d %d",&N,&K);
      |   ^~~~~
a.cc:9:17: error: 'h' was not declared in this scope
    9 |     scanf("%d",&h[i]);
      |                 ^
a.cc:13:10: error: 'h' was not declared in this scope
   13 |       if(h[i]<h[k]){
      |          ^
a.cc:14:9: error: 'tmp' was not declared in this scope
   14 |         tmp=h[i];
      |         ^~~
a.cc:22:9: error: 'h' was not declared in this scope
   22 |     DIF=h[i+K]-h[i];
      |         ^
a.cc:28:3: error: 'reutrn' was not declared in this scope
   28 |   reutrn 0;
      |   ^~~~~~
Language: C++

#include<iostream>
#include<algorithm>

using namespace std;

int main(){
  
  int n, k;
  cin >> n >> k;
  
  int a[n];
  for(int i = 0; i < n; i++) cin >> a[i];
  
  sort(a, a + n);
  
  
  int mi = 1000000005;
  
  for(int i = 1; i < n; i++){
      mi = min(mi, a[i] - a[i-1]) 
   }
  
  cout << mi;
  
  
  return 0; 
}


Compiler output:
a.cc: In function 'int main()':
a.cc:20:34: error: expected ';' before '}' token
   20 |       mi = min(mi, a[i] - a[i-1])
      |                                  ^
      |                                  ;
   21 |    }
      |    ~
Language: C++

#include<iostream>
#include<algorithm>

using namespace std;

int main(){
  
  int n, k;
  cin >> n >> k;
  
  int a[n];
  for(int i = 0; i < n; i++) cin >> a[i];
  
  sort(a, a + n);
  
  
  int mi = 1000000005;
  
  for(int i = 1; i < n; i++){
      mi = min(mi, a[i] - a[i-1]) 
   }
  
  cout << mi
  
  
  return 0; 
}

Compiler output:
a.cc: In function 'int main()':
a.cc:20:34: error: expected ';' before '}' token
   20 |       mi = min(mi, a[i] - a[i-1])
      |                                  ^
      |                                  ;
   21 |    }
      |    ~                              
a.cc:23:13: error: expected ';' before 'return'
   23 |   cout << mi
      |             ^
      |             ;
......
   26 |   return 0;
      |   ~~~~~~
Language: C++

#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstdio>
#define ll long long
#define INF 1e+7
#define MOD 1000000007
using namespace std;



int main(){
    int N;
    cin >> N;
    int K;
    cin >> K;
    ll h[N];
    for(int i=0; i<N; i++){
        cin >> h[i];
    }
    sort(h,h+N);
    
    int ans=INF;
    for(int i=0; i+K<=N; i++){
        ans=min(ans,h[i+K-1]-h[i]);
    }
    cout<<ans<<endl;
    
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:34:16: error: no matching function for call to 'min(int&, long long int)'
   34 |         ans=min(ans,h[i+K-1]-h[i]);
      |             ~~~^~~~~~~~~~~~~~~~~~~
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:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:34:16: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   34 |         ans=min(ans,h[i+K-1]-h[i]);
      |             ~~~^~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281: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:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:34:16: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   34 |         ans=min(ans,h[i+K-1]-h[i]);
      |             ~~~^~~~~~~~~~~~~~~~~~~
Language: C

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

const int LIM = 1e9;

int N, K;
int h[LIM];

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

    int ans = 1e9;
    for(int i=0; i<N-K; i++){
        ans = min(ans, h[i+K-1] - h[i]);
    }

    cout << ans << endl;

    return 0;
}

Compiler output:
main.c:1:10: fatal error: iostream: No such file or directory
    1 | #include <iostream>
      |          ^~~~~~~~~~
compilation terminated.
Language: C++

#include<iostream>
#include<vector>
#include<altorithm>
using namespace std;
int main()
{
    int n, k;
    cin >> n >> k;
  	std::vector<int> h;
    for (int i = 0; i < n; ++i) {
      int tmp;
      cin >> tmp;
      h.push_back(tmp);
    }
    std::sort(h.begin(), h.end());
    int min = h.at(n-1);
    for (int i = 0; i < n - (k - 1); ++i) {
      int tmp = h.at(n + k - 1) - h.at(n);
      if (min > tmp) min = tmp;
    }
    // 出力
    cout << min << endl;
    return 0;
}

Compiler output:
a.cc:3:9: fatal error: altorithm: No such file or directory
    3 | #include<altorithm>
      |         ^~~~~~~~~~~
compilation terminated.
Language: C++

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
    int n, k;
    cin >> n >> k;
  	std::vector<int> h;
    for (int i = 0; i < n; ++i) {
      int tmp;
      cin >> tmp;
      h.push_back(tmp);
    }
    std::sort(h.begin(), h.end());
    int min = h.end();
    for (int i = 0; i < n - (k - 1); ++i) {
      int tmp = h.at(n + k - 1) - h.at(n);
      if (min > tmp) min = tmp;
    }
    // 出力
    cout << min << endl;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:16:20: error: cannot convert 'std::vector<int>::iterator' to 'int' in initialization
   16 |     int min = h.end();
      |               ~~~~~^~
      |                    |
      |                    std::vector<int>::iterator
Language: C++

#include<iostream>
#include<vector>
using namespace std;
int main()
{
    int n, k;
    cin >> n >> k;
  	std::vector<int> h;
    for (int i = 0; i < n; ++i) {
      int tmp;
      cin >> tmp;
      h.push_back(tmp);
    }
    std::sort(h.begin(), h.end());
    int min = h.end();
    for (int i = 0; i < n - (k - 1); ++i) {
      int tmp = h.at(n + k - 1) - h.at(n);
      if (min > tmp) min = tmp;
    }
    // 出力
    cout << min << endl;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:14:10: error: 'sort' is not a member of 'std'; did you mean 'qsort'?
   14 |     std::sort(h.begin(), h.end());
      |          ^~~~
      |          qsort
a.cc:15:20: error: cannot convert 'std::vector<int>::iterator' to 'int' in initialization
   15 |     int min = h.end();
      |               ~~~~~^~
      |                    |
      |                    std::vector<int>::iterator
Language: C++

#include<iostream>
using namespace std;
int main()
{
    int n, k;
    cin >> n >> k;
  	std::vector<int> h;
    for (int i = 0; i < n; ++i) {
      int tmp;
      cin >> tmp;
      h.push_back(tmp);
    }
    std::sort(h.begin(), h.end());
    int min = h.end();
    for (int i = 0; i < n - (k - 1); ++i) {
      int tmp = h.at(n + k - 1) - h.at(n);
      if (min > tmp) min = tmp;
    }
    // 出力
    cout << min << endl;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:7:14: error: 'vector' is not a member of 'std'
    7 |         std::vector<int> h;
      |              ^~~~~~
a.cc:2:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
    1 | #include<iostream>
  +++ |+#include <vector>
    2 | using namespace std;
a.cc:7:21: error: expected primary-expression before 'int'
    7 |         std::vector<int> h;
      |                     ^~~
a.cc:11:7: error: 'h' was not declared in this scope
   11 |       h.push_back(tmp);
      |       ^
a.cc:13:10: error: 'sort' is not a member of 'std'; did you mean 'qsort'?
   13 |     std::sort(h.begin(), h.end());
      |          ^~~~
      |          qsort
a.cc:13:15: error: 'h' was not declared in this scope
   13 |     std::sort(h.begin(), h.end());
      |               ^
Language: C++

#include<iostream>
#include<string>
#include<math.h>
#include<algorithm>
#include<vector>
using namespace std;
int main() {
	int N, K;
	int ans = INT_MAX;
	cin >> N >> K;
	vector <int> h(N);
	for (int i = 0; i < N; i++)cin >> h[i];
	sort(h.begin(), h.end());
	for (int i = 0; i < N; i++)cout << h[i] << endl;
	for (int i = 0; i < N - K + 1; i++) {
		if (ans > h[i+K-1] - h[i]) ans = h[i+K-1] - h[i];
	}
	cout << ans << endl;
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:9:19: error: 'INT_MAX' was not declared in this scope
    9 |         int ans = INT_MAX;
      |                   ^~~~~~~
a.cc:6:1: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
    5 | #include<vector>
  +++ |+#include <climits>
    6 | using namespace std;
Language: Java

import java.util.Scanner;
import java.lang.Math;
import java.lang.StringBuilder;
import java.util.regex.Pattern;
import java.util.Arrays;


    public class Main {
        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            
            int n = sc.nextInt();
            int k = sc.nextInt();
            int[] A=new int[n];
            
        
            for(int i=0; i<n; i++){
                A[i] = sc.nextInt();
            }
            
            Arrays.sort(A);
            
            
            long min = 100000000000;
            for(int h=0; h<n-k+1; h++){
            min = Math.min(min,A[h+k-1] - A[h]);
            }
            System.out.println(min);
        }

Compiler output:
Main.java:24: error: integer number too large
            long min = 100000000000;
                       ^
Main.java:29: error: reached end of file while parsing
        }
         ^
2 errors
Language: Java

import java.util.Scanner;
import java.lang.Math;
import java.lang.StringBuilder;
import java.util.regex.Pattern;
import java.util.Arrays;


    public class Main {
        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            
            int n = sc.nextInt();
            int k = sc.nextInt();
            int[] A=new int[n];
            
        
            for(int i=0; i<n; i++){
                A[i] = sc.nextInt();
            }
            
            Arrays.sort(A);
            
            
            int min = 100000000000;
            for(int h=0; h<n-k+1; h++){
            min = Math.min(min,A[h+k-1] - A[h]);
            }
            System.out.println(min);
        }
    }


Compiler output:
Main.java:24: error: integer number too large
            int min = 100000000000;
                      ^
1 error
Language: C++

#include<iostream>
using namespace std;

int main(){
    int N,K;
    cin >> N >> K;
    int h[N];
    for(int i=0;i<N;i++){
        cin >> h[i];
    }
    sort(h,h+N);
    int d_min=1000000000;
    for(int i=0;i<=N-K;i++){
        int diff = h[i+K-1] - h[i];
        if (diff < d_min) d_min = diff;
    }
    cout << d_min << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:11:5: error: 'sort' was not declared in this scope; did you mean 'short'?
   11 |     sort(h,h+N);
      |     ^~~~
      |     short
Language: C++

// #include<bits/stdc++.h>
#include <iostream>
#include <vector>
#include <cstdio>
#define FOR(i,a,b) for(i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
using namespace std;

int sa(int a[],int n,int k){

	int x=1000000000,i,s;

	for(i=0;i<n;i++){

		s=a[k+i]-a[i];

		if(x>s)
			x=s;

	}

	return x;
}

int main(){

	int N,K,h[100001],i;

	scanf("%d%d",&N,&K);

	REP(i,N)
	scanf("%d",&h[i]);

	sort(h,h+N);

	printf("%d\n",sa(h,N-K+1,K-1));

	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:34:9: error: 'sort' was not declared in this scope; did you mean 'short'?
   34 |         sort(h,h+N);
      |         ^~~~
      |         short
Language: C++

#include<bits/stdc++.h>
 using namespace std;
  int n,i,k;
  int a[100005];
  int main()
  {
   cin>>n>>k;
   for(i=0;i<n;++i) cin>>a[i];
   sort(a,a+n);
   minn=a[k-1]-a[0];
   for(i=0;i<n-k;++i) minn=min(minn,a[i+k-1]-a[i]);
   cout<<minn<<endl;
   return 0;
  }

Compiler output:
a.cc: In function 'int main()':
a.cc:10:4: error: 'minn' was not declared in this scope
   10 |    minn=a[k-1]-a[0];
      |    ^~~~
Language: C++

#include<bits/stdc++.h>
 using namespace std;
  int n,i,k,minn=2100000000;
  int a[100005];
  int main()
  {
   cin>>n>>k;
   for(i=0;i<n;++i) cin>>a[i];
   sort(a,a+n);
   for(i=0;i<n-k;++i) minn=min(minn,a[i+k]-a[i]);
   cout<<minn<<endl;
   return 0;
  ]

Compiler output:
a.cc: In function 'int main()':
a.cc:13:3: error: expected primary-expression before ']' token
   13 |   ]
      |   ^
a.cc:13:4: error: expected '}' at end of input
   13 |   ]
      |    ^
a.cc:6:3: note: to match this '{'
    6 |   {
      |   ^
Language: C++

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

using std::cout;
using std::endl;
using std::cin;

int main()
{
	int N;
	int K;

	cin >> N;
	cin >> K;

	std::vector<int> H;
	int h;

	for (int i = 0; i < N; i++) {
		cin >> h;
		H.push_back(h);
	}

	std::sort(H.begin(), H.end());

	int M = INT_MAX;
	int b;

	for (int i = 0; i <= N - K; i++) {
		b = H[i + K - 1] - H[i];
		if (M > b) {
			M = b;
		}
	}

	cout << M << endl;

	return 0;
}

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

#include<iostream>
using namespace std;

int main() {
  int N, K;
  int trH[100001];
  cin >> N >> K;
  for (int i = 0; i < N; ++i) cin >> trH[i];
  sort(&trH[0], &trH[N]);
  int mind;
  for (int f = 0; f < N - K + 1; ++f) {
    int d = trH[f + K - 1] - trH[f];
    if (d < mind) mind = d;
  }
  cout << mind << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:9:3: error: 'sort' was not declared in this scope; did you mean 'short'?
    9 |   sort(&trH[0], &trH[N]);
      |   ^~~~
      |   short
Language: C++

#include<iostream>
using namespace std;

int main() {
  int N, K;
  int trH[100001];
  cin >> N >> K;
  for (int i = 0; i < N; ++i) cin >> trH[i];
  sort(trH, trH + N);
  int mind;
  for (int f = 0; f < N - K + 1; ++f) {
    int d = trH[f + K - 1] - trH[f];
    if (d < mind) mind = d;
  }
  cout << mind << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:9:3: error: 'sort' was not declared in this scope; did you mean 'short'?
    9 |   sort(trH, trH + N);
      |   ^~~~
      |   short
Language: C++

#include<iostream>

int main(){
    int N, K, h[1000000001];
    std::cin >> N >> K;
    for(int i=1; i<=N; ++i) std::cin >> h[i];
    std::sort(h+1, h+N);
    int min = 2147483647;
    for(int i=1; i <= N-K; ++i){
        if(h[i+K] - h[i] < min) min = h[i+K] - h[i];
    }
    std::cout << min << std::endl;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:7:10: error: 'sort' is not a member of 'std'; did you mean 'qsort'?
    7 |     std::sort(h+1, h+N);
      |          ^~~~
      |          qsort
Language: C++

#include <stdio.h>
#include <algorithm>
using namespace std;
int main()
{
	int a[100050];
	int e, i;
	int n, m;
	int t;
	int min;
	int sign;
	int flag = 1;
	while (scanf("%d %d", &n, &m) != EOF)
	{
		flag = 1;
		sign = 0;
		min = 1000000000;
		for (e = 0; e < n; e++)
		{
			scanf("%d", &a[e]);
		}
        sort(a, a + n)
		for (e = 0; e < n - m + 1; e++)
		{
			if( (a[e + m - 1] - a[e]) < min)
			{
				min = a[e + m - 1] - a[e];
				sign = 1;
			}
		}
		if (sign == 0)
		{
			min = 0;
		}
		printf("%d\n",min);



	}

	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:22:23: error: expected ';' before 'for'
   22 |         sort(a, a + n)
      |                       ^
      |                       ;
   23 |                 for (e = 0; e < n - m + 1; e++)
      |                 ~~~    
a.cc:23:47: error: expected ';' before ')' token
   23 |                 for (e = 0; e < n - m + 1; e++)
      |                                               ^
      |                                               ;
Language: C

#include <stdio.h>
#include <stdlib.h>

int compar(const void *a, const void *b)
{
     return *(int *)a - *(int *)b;
}

int main(void){
	int n,k,h[100001],i,j,tmp,min=100000;
  	scanf("%d %d", &n,&k);
  	
  	for(i=0;i<n;i++){
		scanf("%d", &h[i]);
    }
  
  qsort(h,n,,compar);
  
  
  	for(i=0;i<n-k+2;i++){
      	if(h[i+k-1]-h[i]<min){
          	min=h[i+k-1]-h[i];
        }
    }
  
  	printf("%d", min);
}



Compiler output:
main.c: In function 'main':
main.c:17:13: error: expected expression before ',' token
   17 |   qsort(h,n,,compar);
      |             ^
Language: C

#include <stdio.h>
#include <stdlib.h>

int compar(const void *a,const void *b){
  return *(int *)a - (int *)b;
}

int main(void){
	int n,k,h[100001],i,j,tmp,min=100000;
  	scanf("%d %d", &n,&k);
  	
  	for(i=0;i<n;i++){
		scanf("%d", &h[i]);
    }
  
  qsort(h,n,4,compar);
  
  
  	for(i=0;i<k;i++){
      	if(h[i+k-1]-h[i]<min){
          	min=h[i+k-1]-h[i];
        }
    }
  
  	printf("%d", min);
}



Compiler output:
main.c: In function 'compar':
main.c:5:20: error: invalid operands to binary - (have 'int' and 'int *')
    5 |   return *(int *)a - (int *)b;
      |          ~~~~~~~~~ ^ ~~~~~~~~
      |          |           |
      |          int         int *
Language: C

#include<stdio.h>
int main(void) {
  int N,K,H[100000],ans=1000000000,h,len,i;
  scanf("%d %d",&N,&K);
  len=N;
  for(i=0;i<N;i++)scanf("%d",&H[i]);
  while(len!=1) {
    for(i=0;i<len-1;i++)if(H[i]>H[i+1])h=H[i];H[i]=H[i+1];H[i+1]=h;
    len--
  }
  for(i=0;i<N-K+1;i++)if(ans>H[i+K-1]-H[i])ans=H[i+K-1]-H[i];
  printf("%d",ans);
  return 0;
}

Compiler output:
main.c: In function 'main':
main.c:9:10: error: expected ';' before '}' token
    9 |     len--
      |          ^
      |          ;
   10 |   }
      |   ~
Language: C++

#include<iostream>
#include<algorithm>
using namespace std;main(){int i,n,k,h[9<<14],m=1e9,x;cin>>n>>k;for(i=n;i--;)cin>>h[i];sort(h,h+n);for(i=n-k+1;i--;m<?x)x=h[i+k-1]-h[i];cout<<m;}

Compiler output:
a.cc:3:21: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    3 | using namespace std;main(){int i,n,k,h[9<<14],m=1e9,x;cin>>n>>k;for(i=n;i--;)cin>>h[i];sort(h,h+n);for(i=n-k+1;i--;m<?x)x=h[i+k-1]-h[i];cout<<m;}
      |                     ^~~~
a.cc: In function 'int main()':
a.cc:3:118: error: expected primary-expression before '?' token
    3 | using namespace std;main(){int i,n,k,h[9<<14],m=1e9,x;cin>>n>>k;for(i=n;i--;)cin>>h[i];sort(h,h+n);for(i=n-k+1;i--;m<?x)x=h[i+k-1]-h[i];cout<<m;}
      |                                                                                                                      ^
a.cc:3:120: error: expected ':' before ')' token
    3 | using namespace std;main(){int i,n,k,h[9<<14],m=1e9,x;cin>>n>>k;for(i=n;i--;)cin>>h[i];sort(h,h+n);for(i=n-k+1;i--;m<?x)x=h[i+k-1]-h[i];cout<<m;}
      |                                                                                                                        ^
      |                                                                                                                        :
a.cc:3:120: error: expected primary-expression before ')' token
Language: C++

#include <stdio.h>
int main()
{
	int a[100005];
	int e, i;
	int n, m;
	int t;
	int min;
	int sign;
	while (scanf("%d %d", &n, &m) != EOF)
	{
		sign = 0
		min = 100000000;
		for (e = 0; e < n; e++)
		{
			scanf("%d", &a[e]);
		}
		for (e = 0; e < n; e++)
		{
			for (i = e + 1; i < n; i++)
			{
				if(a[e] > a[i])
				{
					t = a[e];
					a[e] = a[i];
					a[i] = t;
				}
			}	
		}
		for (e = 0; e < n-2; e++)
		{
			if( (a[e + 2] - a[e]) < min)
			{
				min = a[e + 2] - a[e];
				sign = 1
			}
		}
		if (sign == 0)
		{
			min = 0;
		}
		printf("%d\n",min);



	}

	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:12:25: error: expected ';' before 'min'
   12 |                 sign = 0
      |                         ^
      |                         ;
   13 |                 min = 100000000;
      |                 ~~~      
a.cc:35:41: error: expected ';' before '}' token
   35 |                                 sign = 1
      |                                         ^
      |                                         ;
   36 |                         }
      |                         ~
Language: C++

#include <iostream>
using namespace std;

int main() {
  int N, K, ans = 1000000007;
  cin >> N >> K;

  int h[N + 5];
  for (int i = 0; i < N; i++) {
    cin >> h[i];
  }
  sort(h, h + N);

  for (int i = 0; i <= N - K; i++) {
    ans = min(ans, h[right] - h[i + K - 1]);
  }
  cout << ans << endl;

  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:12:3: error: 'sort' was not declared in this scope; did you mean 'short'?
   12 |   sort(h, h + N);
      |   ^~~~
      |   short
a.cc:15:21: error: invalid types 'int [(N + 5)][std::ios_base&(std::ios_base&)]' for array subscript
   15 |     ans = min(ans, h[right] - h[i + K - 1]);
      |                     ^
Language: C++

#include<iostream>
using namespace std;main(){int i,n,k,h[9<<14],m=1e9,x;cin>>n>>k;for(i=n;i--;)cin>>h[i];sort(h,h+n);for(i=n-k+1;i--;m=m>x?x:m)x=h[i+k-1]-h[i];cout<<x;}


Compiler output:
a.cc:2:21: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    2 | using namespace std;main(){int i,n,k,h[9<<14],m=1e9,x;cin>>n>>k;for(i=n;i--;)cin>>h[i];sort(h,h+n);for(i=n-k+1;i--;m=m>x?x:m)x=h[i+k-1]-h[i];cout<<x;}
      |                     ^~~~
a.cc: In function 'int main()':
a.cc:2:88: error: 'sort' was not declared in this scope; did you mean 'short'?
    2 | using namespace std;main(){int i,n,k,h[9<<14],m=1e9,x;cin>>n>>k;for(i=n;i--;)cin>>h[i];sort(h,h+n);for(i=n-k+1;i--;m=m>x?x:m)x=h[i+k-1]-h[i];cout<<x;}
      |                                                                                        ^~~~
      |                                                                                        short
Language: C++

#include<iostream>
using namespace std;main(){int i,n,k,h[1e5],m=1e9,x;cin>>n>>k;for(i=n;i--;)cin>>h[i];sort(h,h+n);for(i=n-k+1;i--;m=m>x?x:m)x=h[i+k-1]-h[i];cout<<x;}

Compiler output:
a.cc:2:21: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    2 | using namespace std;main(){int i,n,k,h[1e5],m=1e9,x;cin>>n>>k;for(i=n;i--;)cin>>h[i];sort(h,h+n);for(i=n-k+1;i--;m=m>x?x:m)x=h[i+k-1]-h[i];cout<<x;}
      |                     ^~~~
a.cc: In function 'int main()':
a.cc:2:40: error: conversion from 'double' to 'long unsigned int' in a converted constant expression
    2 | using namespace std;main(){int i,n,k,h[1e5],m=1e9,x;cin>>n>>k;for(i=n;i--;)cin>>h[i];sort(h,h+n);for(i=n-k+1;i--;m=m>x?x:m)x=h[i+k-1]-h[i];cout<<x;}
      |                                        ^~~
a.cc:2:40: error: could not convert '1.0e+5' from 'double' to 'long unsigned int'
    2 | using namespace std;main(){int i,n,k,h[1e5],m=1e9,x;cin>>n>>k;for(i=n;i--;)cin>>h[i];sort(h,h+n);for(i=n-k+1;i--;m=m>x?x:m)x=h[i+k-1]-h[i];cout<<x;}
      |                                        ^~~
      |                                        |
      |                                        double
a.cc:2:40: error: size of array 'h' has non-integral type 'double'
a.cc:2:86: error: 'sort' was not declared in this scope; did you mean 'short'?
    2 | using namespace std;main(){int i,n,k,h[1e5],m=1e9,x;cin>>n>>k;for(i=n;i--;)cin>>h[i];sort(h,h+n);for(i=n-k+1;i--;m=m>x?x:m)x=h[i+k-1]-h[i];cout<<x;}
      |                                                                                      ^~~~
      |                                                                                      short
Language: C++

#include<stdio.h>
#include<stdlib.h>

#define SENTINEL 1000000000

long long int count = 0;

void mergeSort(int A[], int left, int right) {
	int i, mid;
	if (left + 1 < right) {
		mid = (left + right) / 2;
		mergeSort(A, left, mid);
		mergeSort(A, mid, right);
		merge(A, left, mid, right);
	}
}



void merge(int A[], int left, int mid, int right) {
	int n1, n2, i, j, k;
	int *L, *R;
	n1 = mid - left;
	n2 = right - mid;
	L = (int *)malloc(sizeof(int)*(n1 + 1));
	R = (int *)malloc(sizeof(int)*(n2 + 1));
	for (i = 0; i <= n1 - 1; i++) {
		L[i] = A[left + i];
	}
	for (j = 0; j <= n2 - 1; j++) {
		R[j] = A[mid + j];
	}
	L[n1] = SENTINEL;
	R[n2] = SENTINEL;
	i = 0;
	j = 0;
	for (k = left; k <= right - 1; k++) {
		if (L[i] <= R[j]) {
			A[k] = L[i];
			i++;
			count++;
		}
		else {
			A[k] = R[j];
			j++;
			count++;
		}
	}
	free(L);
	free(R);
}
long long int min(long long int n, long long int tmp[], long long int *num, long long int *M) {
	long long int min_memo = tmp[0];
	long long int min_num = 0;
	for (int i = 1; i < n; i++) {
		if (min_memo > tmp[i]) {
			min_memo = tmp[i];
			min_num = i;
		}
	}
	*num = min_num;
	*M = min_memo;
	return 0;
}

main() {
	int A[500000];
    int k;
	long long int n,num,m;
	long long int s[500000] = {};
	scanf("%d%d", &n,&k);
	for (int i = 0; i < n; i++) {
		scanf("%d", &A[i]);
	}
	mergeSort(A, 0, n);
	for (int i = n-1; i >= k-1; i--) {
		s[i - k+1] = A[i] - A[i - k+1];
     
		
	}
	min(n-k+1, s, &num, &m);
	printf("%lld", m);
	return 0;
}
	


Compiler output:
a.cc: In function 'void mergeSort(int*, int, int)':
a.cc:14:17: error: 'merge' was not declared in this scope
   14 |                 merge(A, left, mid, right);
      |                 ^~~~~
a.cc: At global scope:
a.cc:66:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   66 | main() {
      | ^~~~
Language: C

#include <stdio.h>
#include <stdlib.h>
#define MIN(a,b) (a<b?a:b)
int cmp(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}

void mergeSortWithIdx(int A[], int idx[], int left, int right)
{
    int i;
    int n = right-left;
    for(i=0;i<n;i++)
        idx[i] = i;
    mergeSort(A, idx, left, right);
}


void merge(int A[], int idx[], int left, int mid, int right)
{
    int n1, n2, i, j, k;
    int *L, *R;
    int *L_idx, *R_idx;
    n1 = mid - left;
    n2 = right - mid;
    L = (int*)malloc(sizeof(int)*(n1+1));
    R = (int*)malloc(sizeof(int)*(n2+1));
    L_idx = (int*)malloc(sizeof(int)*(n1+1));
    R_idx = (int*)malloc(sizeof(int)*(n2+1));
    for(i=0;i<n1;i++) {
        L[i] = A[left+i];
        L_idx[i] = idx[left+i];
    }
    for(j=0;j<n2;j++) {
        R[j] = A[mid+j];
        R_idx[j] = idx[mid+j];
    }
    L[n1] = SENTINEL;
    R[n2] = SENTINEL;
    L_idx[n1] = SENTINEL;
    R_idx[n2] = SENTINEL;
    i=0;
    j=0;
    for(k=left;k<right;k++) {
        if(L[i] <= R[j]) {
            A[k] = L[i];
            idx[k] = L_idx[i];
            i++;
        } else {
            A[k] = R[j];
            idx[k] = R_idx[j];
            j++;
        }
    }
    free(L);
    free(R);
}


void mergeSort(int A[], int idx[], int left, int right)
{
    int i, mid;
    if(left+1 < right) {
        mid = (left + right) / 2;
        mergeSort(A, idx, left, mid);
        mergeSort(A, idx, mid, right);
        merge(A, idx, left, mid, right);
    }
}

int main()
{
    int n, k, i, h[100000],idx[100000];
    int min=1000000000;
    scanf("%d %d",&n, &k);
    for(i=0;i<n;i++){
        scanf("%d",&h[i]);
    }
    mergeSort(h,idx,0,n);
    for(i=0;i<=n-k;i++) {
        min = MIN(min, h[i+k-1]-h[i]);
    
    }
    printf("%d",min);
    return 0;
}

Compiler output:
main.c: In function 'mergeSortWithIdx':
main.c:15:5: error: implicit declaration of function 'mergeSort' [-Wimplicit-function-declaration]
   15 |     mergeSort(A, idx, left, right);
      |     ^~~~~~~~~
main.c: In function 'merge':
main.c:38:13: error: 'SENTINEL' undeclared (first use in this function)
   38 |     L[n1] = SENTINEL;
      |             ^~~~~~~~
main.c:38:13: note: each undeclared identifier is reported only once for each function it appears in
main.c: At top level:
main.c:60:6: warning: conflicting types for 'mergeSort'; have 'void(int *, int *, int,  int)'
   60 | void mergeSort(int A[], int idx[], int left, int right)
      |      ^~~~~~~~~
main.c:15:5: note: previous implicit declaration of 'mergeSort' with type 'void(int *, int *, int,  int)'
   15 |     mergeSort(A, idx, left, right);
      |     ^~~~~~~~~
Language: C++

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
const int max = 1e5 + 5;
int a[max];
int main(){
	int T;
	int N;
	int sum = 0;
	scanf("%d %d", &T, &N);
	for(int i = 1; i <= T; i++){
		scanf("%d ", &a[i]);	
	}
	sort(a + 1, a + 1 + T);
	sum - a[T] - a[T - N];
	printf("%d\n", sum);
}

Compiler output:
a.cc:7:7: error: reference to 'max' is ambiguous
    7 | int a[max];
      |       ^~~
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:3:
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidates are: '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:5706:5: note:                 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
In file included from /usr/include/c++/14/algorithm:60:
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:                 '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:257:5: note:                 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
a.cc:6:11: note:                 'const int max'
    6 | const int max = 1e5 + 5;
      |           ^~~
a.cc: In function 'int main()':
a.cc:14:31: error: 'a' was not declared in this scope
   14 |                 scanf("%d ", &a[i]);
      |                               ^
a.cc:16:14: error: 'a' was not declared in this scope
   16 |         sort(a + 1, a + 1 + T);
      |              ^
Language: C++

#include<bits/stdc++.h>
using namespace std;
int main(){
  int n, k, mn = 1e+9;
  cin >> n >> k;
  int h[n];
  for(int i=0;i<n;i++){
    cin >> h[i];
  }
  sort(h, h+n, greater<int>());
  for(int i=0;i<=n-k;i++){
    mn = min(mn,h[i]-h[i+k-1]);
  }
  cout << mn << endl;


Compiler output:
a.cc: In function 'int main()':
a.cc:14:22: error: expected '}' at end of input
   14 |   cout << mn << endl;
      |                      ^
a.cc:3:11: note: to match this '{'
    3 | int main(){
      |           ^
Language: C++

#include <iostream>
using namespace std;

int main(){
  int n; cin >> n;
  int k; cin >> k;
  int A[100010];
  for(int i=0; i<n; ++i) cin >> A[i];
  sort(A, A+n);
  cout << A[n-1] - A[n-k] << endl;
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:9:3: error: 'sort' was not declared in this scope; did you mean 'short'?
    9 |   sort(A, A+n);
      |   ^~~~
      |   short
Language: C++

#include <iostream>
using namespace std;

int main(){
  int n; cin >> n;
  int k; cin >> k;
  int A[100010];
  for(int i=0; i<n; ++i) cin >> A[i];
  sort(A, A+n);
  cout << abs( A[n-1] - A[n-k]) << endl;
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:9:3: error: 'sort' was not declared in this scope; did you mean 'short'?
    9 |   sort(A, A+n);
      |   ^~~~
      |   short
Language: Java

import java.util.*;
public class Main {
	public static void main(String[] args)
	{
		//変数
		int min=10*9+1;
		//入力
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K=sc.nextInt();
		ArrayList<int> h=new ArrayList<int>();
		for(int i=0;i<N;i++)
		{
			int hi=sc.nextInt();
			h.add(hi);
		}
		//処理
		Collections.sort(h);
		//System.out.println(Arrays.toString(h));
		for(int i=0;i<m;i++)
		{
			if(i>N-K)
			{
				break;
			}else
			{
				int b=c.get(i+K-1)-c.get(i);
				if(min>b)
				{
					min=b;
				}
			}
		}
		// 出力
		//System.out.println(Arrays.toString(h));
		System.out.println(min);
	}
}

Compiler output:
Main.java:11: error: unexpected type
		ArrayList<int> h=new ArrayList<int>();
		          ^
  required: reference
  found:    int
Main.java:11: error: unexpected type
		ArrayList<int> h=new ArrayList<int>();
		                               ^
  required: reference
  found:    int
Main.java:20: error: cannot find symbol
		for(int i=0;i<m;i++)
		              ^
  symbol:   variable m
  location: class Main
Main.java:27: error: cannot find symbol
				int b=c.get(i+K-1)-c.get(i);
				      ^
  symbol:   variable c
  location: class Main
Main.java:27: error: cannot find symbol
				int b=c.get(i+K-1)-c.get(i);
				                   ^
  symbol:   variable c
  location: class Main
5 errors
Language: C

#include <stdio.h>
#include <stdlib.h>
typedef int value_type; /* ソートするキーの型 */

/* x, y, z の中間値を返す */
value_type med3(value_type x, value_type y, value_type z) {
    if (x < y) {
        if (y < z) return y; else if (z < x) return x; else return z;
    } else {
        if (z < y) return y; else if (x < z) return x; else return z;
    }
}

/* クイックソート
 * a     : ソートする配列
 * left  : ソートするデータの開始位置
 * right : ソートするデータの終了位置
 */
void quicksort(value_type a[], int left, int right) {
    if (left < right) {
        int i = left, j = right;
        value_type tmp, pivot = med3(a[i], a[i + (j - i) / 2], a[j]); /* (i+j)/2 ではオーバーフローしてしまう */
        while (1) { /* a[] を pivot 以上と以下の集まりに分割する */
            while (a[i] < pivot) i++; /* a[i] >= pivot となる位置を検索 */
            while (pivot < a[j]) j--; /* a[j] <= pivot となる位置を検索 */
            if (i >= j) break;
            tmp = a[i]; a[i] = a[j]; a[j] = tmp; /* a[i], a[j] を交換 */
            i++; j--;
        }
        quicksort(a, left, i - 1);  /* 分割した左を再帰的にソート */
        quicksort(a, j + 1, right); /* 分割した右を再帰的にソート */
    }
}
void quickSort(int numbers[], int array_size)
{
    q_sort(numbers, 0, array_size - 1);
}


#include <stdio.h>
#include <stdlib.h>
int main (void){
  int n,i,j,k,stack;
  int distance=1000000000;
  int h[100000];
  scanf("%d%d",&n,&k);
  for(i=0;i<n;i++){
    scanf("%d",&h[i]);
  }
  quickSort(h,n);
  for(i=0;i<=n-k;i++){
    stack=abs(h[i]-h[i+k-1]);
    distance=(distance>stack)?stack:distance;
  }
  printf("%d",distance);
  return 0;
}

Compiler output:
main.c: In function 'quickSort':
main.c:36:5: error: implicit declaration of function 'q_sort'; did you mean 'qsort'? [-Wimplicit-function-declaration]
   36 |     q_sort(numbers, 0, array_size - 1);
      |     ^~~~~~
      |     qsort
Language: C++

#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
#include <functional>
#include <numeric>
#include <stack>
#include <tuple>

using namespace std;
int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 100000000;
const long long LINF = 1000000000000000000;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-6;
using pii = std::pair<int, int>;
using ll=long long;  
using pLL = std::pair<ll, ll>;

#define SORT(v) std::sort(v.begin(), v.end())
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,K;
    ll ans=LINF;
    cin >> N >> K;
    vector<ll> a(N);
    for(int i=0;i<N;++i){
        cin >> a[i];
    }
    SORT(a);
    for(size_t i=0;i<N-K+1;i++){
        ll temp=a[i+K-1]-a[i]
        ans=min(ans,temp);
    }
    cout << ans <<endl;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:44:9: error: expected ',' or ';' before 'ans'
   44 |         ans=min(ans,temp);
      |         ^~~
Language: C

#include <stdio.h>
#include <stdlib.h>
void q_sort(value_type a[], int left, int right) {
    if (left < right) {
        int i = left, j = right;
        value_type tmp, pivot = med3(a[i], a[i + (j - i) / 2], a[j]); /* (i+j)/2 ではオーバーフローしてしまう */
        while (1) { /* a[] を pivot 以上と以下の集まりに分割する */
            while (a[i] < pivot) i++; /* a[i] >= pivot となる位置を検索 */
            while (pivot < a[j]) j--; /* a[j] <= pivot となる位置を検索 */
            if (i >= j) break;
            tmp = a[i]; a[i] = a[j]; a[j] = tmp; /* a[i], a[j] を交換 */
            i++; j--;
        }
        q_sort(a, left, i - 1);  /* 分割した左を再帰的にソート */
        q_sort(a, j + 1, right); /* 分割した右を再帰的にソート */
    }
}
void quickSort(int numbers[], int array_size)
{
    q_sort(numbers, 0, array_size - 1);
}


#include <stdio.h>
#include <stdlib.h>
int main (void){
  int n,i,j,k,stack;
  int distance=1000000000;
  int h[100000];
  scanf("%d%d",&n,&k);
  for(i=0;i<n;i++){
    scanf("%d",&h[i]);
  }
  quickSort(h,n);
  for(i=0;i<=n-k;i++){
    stack=abs(h[i]-h[i+k-1]);
    distance=(distance>stack)?stack:distance;
  }
  printf("%d",distance);
  return 0;
}

Compiler output:
main.c:3:13: error: unknown type name 'value_type'
    3 | void q_sort(value_type a[], int left, int right) {
      |             ^~~~~~~~~~
main.c: In function 'quickSort':
main.c:20:5: error: implicit declaration of function 'q_sort'; did you mean 'qsort'? [-Wimplicit-function-declaration]
   20 |     q_sort(numbers, 0, array_size - 1);
      |     ^~~~~~
      |     qsort
Language: C++

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

int N,K;


int main() {
  int tmp,a,min,c;
    c=0;
    tmp=0;
    min=1000000000;
    cin>>N>>K;
    a=N-K+1;
    int h[N];
    for(int i=0;i<N;i++)
    {
        cin>>h[i];
 
    }
    sort(h, h + N);

    for(int i=0;i<a;i++)
    {
        c=abs(h[i]-h[i+K-1]);
 
        if(c<min)
        {
            min=c;
        }
    }
 
    cout<<b<<endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:32:11: error: 'b' was not declared in this scope
   32 |     cout<<b<<endl;
      |           ^
Language: C++

#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
#include <functional>
#include <numeric>
#include <stack>
#include <tuple>

using namespace std;
int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 100000000;
const long long LINF = 1000000000000000000;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-6;
using pii = std::pair<int, int>;
using ll=long long;  
using pLL = std::pair<ll, ll>;

#define SORT(v) std::sort(v.begin(), v.end())
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,K,x,sum=0;
    cin >> N >> K;
    vector<int> a(N);
    vector<int> b;
    map<int,int> mp;
    for(int i=0;i<N;++i){
        cin >> a[i];
    }
    SORT(a);
    for(int i=0;i<N-K+1;i++){
        ans=min(ans,a[i+K-1]-a[i]);
    }
    cout << ans <<endl;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:44:9: error: 'ans' was not declared in this scope; did you mean 'abs'?
   44 |         ans=min(ans,a[i+K-1]-a[i]);
      |         ^~~
      |         abs
a.cc:46:13: error: 'ans' was not declared in this scope; did you mean 'abs'?
   46 |     cout << ans <<endl;
      |             ^~~
      |             abs
Language: C++

n, k = gets.split.map &:to_i
trees = []
 
n.times do
  trees << gets.to_i
end
 
trees.sort!
ans = 1E9
 
for i in 0 .. n - k
  min = trees[i + k - 1] - trees[i]
  ans = [min, ans].min
end
 
puts ans

Compiler output:
a.cc:1:1: error: 'n' does not name a type
    1 | n, k = gets.split.map &:to_i
      | ^
Language: C++

#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VRSORT(v) sort(v.rbegin(), v.rend());//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,k;
  cin >> n >> k;
  vector<ll> p(n);
  REP(i,n) cin>> p[i];
  VSORT(p)
  ll h_min = INF;
  REP(i,n-k+1){
    int tmp=h[i-k+1] - h[i];
    h_min = min(h_min,tmp);
  }
  cout << h_min << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:32:13: error: 'h' was not declared in this scope
   32 |     int tmp=h[i-k+1] - h[i];
      |             ^
a.cc:33:16: error: no matching function for call to 'min(long long int&, int&)'
   33 |     h_min = min(h_min,tmp);
      |             ~~~^~~~~~~~~~~
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:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:33:16: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   33 |     h_min = min(h_min,tmp);
      |             ~~~^~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281: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:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:33:16: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   33 |     h_min = min(h_min,tmp);
      |             ~~~^~~~~~~~~~~
Language: C++

#include<iostream>
#include<algorithm>
#include<vector>
#include<cctype>
#include<string>
using namespace std;
int main() {
    int n,k;
    cin >>n>>k;
   vector<int> h(n);
   for(int i=0;i<n;i++){
      cin>>h[i];
    }
    sort(h.begin(),h.end(),greater<int>());
    int ans=1000000;
    for(int=0;i<k-1;i++){
        if(ans>h[i]-h[i+k-1])ans=h[i]-h[i+k-1];
    }
    cout << ans<<endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:16:12: error: expected unqualified-id before '=' token
   16 |     for(int=0;i<k-1;i++){
      |            ^
a.cc:16:12: error: expected ';' before '=' token
   16 |     for(int=0;i<k-1;i++){
      |            ^
      |            ;
a.cc:16:12: error: expected primary-expression before '=' token
a.cc:16:15: error: 'i' was not declared in this scope
   16 |     for(int=0;i<k-1;i++){
      |               ^
a.cc:16:20: error: expected ')' before ';' token
   16 |     for(int=0;i<k-1;i++){
      |        ~           ^
      |                    )
a.cc:16:21: error: 'i' was not declared in this scope
   16 |     for(int=0;i<k-1;i++){
      |                     ^
Language: C++

#include <iostream>
#include <cstdlib>

using namespace std;

int main(void){
    int n=0;
    int k=0;
    int h[100];
    int tmp=0;
    int min=0;

    cin >> n >> k;
    
    for(int i=0;i<n;i++){
        cin >> h[i];
    }

    sort(h,h+n);

    min=abs(h[0]-h[2]);

    for(int i=0;i<n-k+1;i++){
        tmp=abs(h[i]-h[i+2]);
        if(min>tmp)min=tmp;
    }

    cout << min << endl;

    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:19:5: error: 'sort' was not declared in this scope; did you mean 'short'?
   19 |     sort(h,h+n);
      |     ^~~~
      |     short
Language: C++

#include <iostream>
#include <cstdlib>

using namespace std;

int main(void){
    int n=0;
    int k=0;
    int h[100000];
    int tmp=0;
    int min=0;

    cin >> n >> k;
    
    for(int i=0;i<n;i++){
        cin >> h[i];
    }

    sort(h,h+n);

    min=abs(h[0]-h[2]);

    for(int i=0;i<n-k+1;i++){
        tmp=abs(h[i]-h[i+2]);
        if(min>tmp)min=tmp;
    }

    cout << min << endl;

    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:19:5: error: 'sort' was not declared in this scope; did you mean 'short'?
   19 |     sort(h,h+n);
      |     ^~~~
      |     short