Language: C++

#include <bits/stdc++.h>
#include <iomanip>
 
using namespace std;
 
typedef long long LL;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<LD, LD> PLDLD;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef vector<char> VB;
 
#define FOR(i,a,b) for(int i=(a);i<(int)(b);++i)
#define REP(i,n) FOR(i,0,n)
#define CLR(a) memset((a), 0 ,sizeof(a))
#define ALL(a) a.begin(),a.end()
#define endl "\n"
 
const LD EPS=1e-10;
const long long INFLL=(LL)(1e9)*(LL)(1e9);
const int INF=1e9;
 
template<class T>
void chmin(T& a, const T b)
{
	if(a>b)
		a=b;
}
template<class T>
void chmax(T& a, const T b)
{
	if(a<b)
		a=b;
}
 
const LL pow(const LL p, const LL q)
{
	LL t=1;
	for(int i=0;i<q;i++)
		t*=p;
	return t;
}

template <typename T>
struct has_iter
{
	private:
		template <typename U>
		static constexpr true_type check(typename U::iterator*);
		template <typename U>
		static constexpr false_type check(...);

	public:
		static constexpr bool value = decltype(check<T>(nullptr))::value;
};


template<typename T, typename U = typename T::iterator>
void print(const T& container)
{
		auto&& first=begin(container), last=end(container);
		auto&& back=prev(last);
		for(auto e=first; e!=last; e=next(e))
			cout<<*e<<" \n"[e==back];
}


extern void* enabler;
template<typename Head, typename enable_if<!has_iter<Head>::value>::type*& = enabler>
void print(const Head& head)
{
	cout<<head<<endl;
}

template<> void print<string>(const string& container)
{
	cout<<container<<endl;
}

template<typename Head, typename... Tail>
void print(const Head& head, const Tail&... tail)
{
	cout<<head<<" ";
	print(tail...);
}

void io_speedup()
{
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);
}

template<typename T>
istream& operator >> (istream& is, vector<T>& vec)
{
	for(T& x: vec) is >> x;
	return is;
}


template<typename T, typename U>
ostream& operator << (ostream& os, const pair<T, U>& p)
{
	os<<'('<<p.first<<", "<<p.second<<')';
	return os;
}

template<typename T>
vector<T> read(int n)
{
	vector<T> t(n);
	cin>>t;
	return t;
}

template<typename T>
T read()
{
	T t;
	cin>>t;
	return t;
}

template<typename Head, typename... Tail>
struct vector_demensions
{
	using type=vector<typename vector_demensions<Tail...>::type>;
};

template<typename Head>
struct vector_demensions<Head> { using type=Head; };

template<typename T>
vector<T> make_vectors(int size, T val)
{
	return vector<T>(size, val);
}

template<typename T=int, typename... Args>
auto make_vectors(int size, Args... tail)
	-> typename vector_demensions<Args..., T>::type
{
	auto val=make_vectors<T>(forward<Args>(tail)...);
	return vector<decltype(val)>(size, val);
}

int select(vector<int> &a, int k) {
  for (int l = 0, r = a.size()-1; l <= r; ) {
    int p = a[(l+r)/2];
    int i = l-1, j = r+1;
    while (1) {
      while (a[++i] < p);
      while (a[--j] > p);
      if (i >= j) break;
      swap(a[i], a[j]);
    }
    if (k == i-l) return a[i];
    else if (k < i-l) { r = i-1; }
    else if (k > i-l) { k -= (i-l+1); l = j+1; }
  }
  return -99999999; // k < 0 || k >= n
}
int main()
{
	int n,k,q;
	cin>>n>>k>>q;
	vector<PII> p(n);
	REP(i,n)
	{
		int a;cin>>a;
		p[i]=PII(a,i);
	}
	sort(ALL(a));
	VB used(n,1);
	int ans=INF*2;
	REP(i,n)
	{
		vector<int> c;
		int cnt=0;
		REP(j,n)
		{
			if(!used[j])
				cnt++;
			else
			{
				if(cnt>0)
					c.push_back(cnt);
				cnt=0;
			}
		}
		int qq=q;
		REP(j,c.size())
		{
			if(c[j]>=k)
				qq-=c[j]-k+1;
		}
		if(qq>0) f=0;
		bool f=1;
		if(!f)
			break;
		chmin(ans, a[i+q].first-a[i].first);
		used[i]=1;
	}
	print(ans);
}


Compiler output:
a.cc: In function 'int main()':
a.cc:176:18: error: 'a' was not declared in this scope
  176 |         sort(ALL(a));
      |                  ^
a.cc:18:16: note: in definition of macro 'ALL'
   18 | #define ALL(a) a.begin(),a.end()
      |                ^
a.cc:200:26: error: 'f' was not declared in this scope
  200 |                 if(qq>0) f=0;
      |                          ^