Language: C++

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

int main(){
  int N,K;
  cin >> N >> K;
  N, K = map(int, input().split());
  vector<int> h(n);
  h = [int(input()) for i in range(N)];
  h.sort();
  cout << min(h[i+K-1] - h[i] for i in range(N-K+1)) << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:7:19: error: 'input' was not declared in this scope; did you mean 'int'?
    7 |   N, K = map(int, input().split());
      |                   ^~~~~
      |                   int
a.cc:7:13: error: missing template arguments before '(' token
    7 |   N, K = map(int, input().split());
      |             ^
a.cc:7:14: error: expected primary-expression before 'int'
    7 |   N, K = map(int, input().split());
      |              ^~~
a.cc:8:17: error: 'n' was not declared in this scope
    8 |   vector<int> h(n);
      |                 ^
a.cc:9:8: error: expected identifier before 'int'
    9 |   h = [int(input()) for i in range(N)];
      |        ^~~
a.cc: In lambda function:
a.cc:9:39: error: expected '{' before ';' token
    9 |   h = [int(input()) for i in range(N)];
      |                                       ^
a.cc: In function 'int main()':
a.cc:9:39: error: no match for 'operator=' (operand types are 'std::vector<int>' and 'main()::<lambda()>')
In file included from /usr/include/c++/14/vector:72,
                 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/vector.tcc:210:5: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(const std::vector<_Tp, _Alloc>&) [with _Tp = int; _Alloc = std::allocator<int>]'
  210 |     vector<_Tp, _Alloc>::
      |     ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/vector.tcc:211:42: note:   no known conversion for argument 1 from 'main()::<lambda()>' to 'const std::vector<int>&'
  211 |     operator=(const vector<_Tp, _Alloc>& __x)
      |               ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
In file included from /usr/include/c++/14/vector:66:
/usr/include/c++/14/bits/stl_vector.h:766:7: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::vector<_Tp, _Alloc>&&) [with _Tp = int; _Alloc = std::allocator<int>]'
  766 |       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:766:26: note:   no known conversion for argument 1 from 'main()::<lambda()>' to 'std::vector<int>&&'
  766 |       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
      |                 ~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_vector.h:788:7: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::initializer_list<_Tp>) [with _Tp = int; _Alloc = std::allocator<int>]'
  788 |       operator=(initializer_list<value_type> __l)
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:788:46: note:   no known conversion for argument 1 from 'main()::<lambda()>' to 'std::initializer_list<int>'
  788 |       operator=(initializer_list<value_type> __l)
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
a.cc:10:5: error: 'class std::vector<int>' has no member named 'sort'
   10 |   h.sort();
      |     ^~~~
a.cc:11:17: error: 'i' was not declared in this scope
   11 |   cout << min(h[i+K-1] - h[i] for i in range(N-K+1)) << endl;
      |                 ^