Language: C++

//#pragma comment(linker,"/STACK:102400000,102400000")
//#include <initializer_list>
#include <fstream>
#include <iostream>
#include <functional>
#include <algorithm>
#include <sstream>
#include <cstring>
#include <vector>
#include <string>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <ctime>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <cassert>
//#include <unordered_map>
//#include <unordered_set>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define eps 1e-8
#define LL_INF 0x3fffffffffffffff
#define INF 0x3f3f3f3f
#define mem(a, b) memset(a, b, sizeof(a))
#define pper(i,n,m) for(int i = n;i >= m; i--)
#define repp(i, n, m) for (int i = n; i <= m; i++)
#define rep(i, n, m) for (int i = n; i < m; i++)
#define sa(n) scanf("%d", &(n))
#define slla(n) scanf("%lld", &(n))
#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define DE(val) cout<<#val<<": "<<val<<endl;
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); repp(i,1,___T)

const int dx44[5] = { 0,-1,-1,1,1 };
const int dy44[5] = { 0,-1,1,-1,1 };

const int dx4[5] = { 0,-1,0,1,0 };
const int dy4[5] = { 0,0,1,0,-1 };
const int dx8[9] = { 0,-1,0,1,0,1,1,-1,-1 };
const int dy8[9] = { 0,0,1,0,-1,1,-1,1,-1 };
const int dx82[9] = { 0,-1,-1,1,1, 2,2,-2,-2 };
const int dy82[9] = { 0,2,-2,2,-2, 1,-1,1,-1 };
const int maxn = 2e3 + 50;
const double PI = acos(-1.0);
const ll mod = 1e9 + 7;

ll po(ll a, ll b, ll mod) { ll res = 1; a %= mod; for (; b; b >>= 1) { if (b & 1)res = res*a%mod; a = a*a%mod; }return res; }
ll gcd(ll a, ll b) { if (a == 0) { return b; } else { return gcd(b%a, a); } }
void extgcd(ll a,ll b,ll& d,ll& x,ll& y){ if(!b){ d=a; x=1; y=0;} else{ extgcd(b,a%b,d,y,x); y-=x*(a/b); }}
ll inverse(ll a,ll n){ ll d,x,y;extgcd(a,n,d,x,y);return d==1?(x+n)%n:-1;}

void YES() { puts("YES"); exit(0); }
void Yes() { puts("Yes");}// exit(0); }
void NO() { puts("NO"); exit(0); }
void No() { puts("No");}// exit(0); }
void one() { puts("-1"); exit(0); }

ll n,k,q;
ll ans;
ll val[maxn];
ll vis[maxn];
ll c[maxn];
void cal(ll x,int f) {
	repp(i,1,n) {
		if(val[i]<x) {
			vis[i]=0;
		} else {
			vis[i]=1;
		}
	}
	int len = 0;
	vector<int>v;
	memset(c,0,sizeof(c));

	int flag = 0;
	repp(i,1,n) {
		if(vis[i]&&i!=f) {
			len++;
			if(len>=k) {
				c[i-k+1]++;
				flag = 1;
			}
		} else {
			if(flag) {
				c[i]--;
				flag=0;
			}
		}
	}
	repp(i,1,n) {
		c[i]+=c[i-1];
	}
	repp(i,1,n) {
		DE(c[i])
		if(c[i]>0) {
			v.push_back(val[i]);
		}
	}
	sort(v.begin(),v.end());

	if(v.size()<q)return;
	DE(ans)
	DE(x)
	ans = min(ans,v[v.size()-q]-x);
	DE(ans)

	if(ans==2) {
		printf("here");
		DE(f)
	}
}

void solve() {
	scanf("%lld%lld%lld",&n,&k,&q);
	repp(i,1,n) {
		scanf("%lld",&val[i]);
	}

	ans = INT_MAX;
	repp(i,1,n){
		cal(val[i],i);
	}

	printf("%lld\n",ans);
}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("i.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    int t;
	//sa(t);
	t = 1;
	repp(i,1,t) {

		solve();	
	}
    // system("pause");
    return 0;
}

Compiler output:
a.cc: In function 'void solve()':
a.cc:129:15: error: 'INT_MAX' was not declared in this scope
  129 |         ans = INT_MAX;
      |               ^~~~~~~
a.cc:22:1: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
   21 | #include <cassert>
  +++ |+#include <climits>
   22 | //#include <unordered_map>