Language: C++

//raja1999
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip> 
//setbase - cout << setbase (16)a; cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 <<endl;prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val

using namespace std;
#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >

//std::ios::sync_with_stdio(false);
ll a[2005];
multiset<ll>se1;
multiset<ll>::iterator it;
pii a1[2005];
vector<set<ll> >se(2005);
set<ll>::iterator it1;
int main(){
	std::ios::sync_with_stdio(false);
	ll n,k,q,ans=inf,i,val,val1,r,j,minn=inf;
	cin>>n>>k>>q;
	rep(i,n){
		cin>>a[i];
		a1[i].ff=a[i];
		a1[i].ss=i;
	} 
	rep(i,n){
		val=i-k+1;
		val=max(val,0);
		minn=inf;
		se1.clear();
		f(j,val,val+k){
			minn=min(minn,a[j]);
			se1.insert(a[j]);
		}
		r=val+k-1;
		se[i].insert(minn);
		f(j,val+1,i+1){
			if(r+1>=n){
				break;
			}
			it=se1.find(a[j-1]);
			se1.erase( it);
			se1.insert(a[r+1]);
			val1=*se1.begin();
			se[i].insert(val1);
			r++;
		}
	}
	sort(a1,a1+n);
	rep(i,n-k+1){
		if(i+q-1<n-k+1){
			if(i>0){
				val=a[i-1];
			}
			else{
				val=0;
			}
			f(j,i,i+q){
				it1=se[a1[j].ss].upper_bound(val);
				if(it1==se[j].end()){
					break;
				}
			}
			if(j==i+q){
				ans=min(ans,a1[i+q-1].ff-a1[i].ff);
			}
		}
	}	
	cout<<ans<<endl;
} 
	

Compiler output:
a.cc: In function 'int main()':
a.cc:63:24: error: no matching function for call to 'max(long long int&, int)'
   63 |                 val=max(val,0);
      |                     ~~~^~~~~~~
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:2:
/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:63:24: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   63 |                 val=max(val,0);
      |                     ~~~^~~~~~~
/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:63:24: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   63 |                 val=max(val,0);
      |                     ~~~^~~~~~~
a.cc:100:40: error: no matching function for call to 'min(long long int&, int)'
  100 |                                 ans=min(ans,a1[i+q-1].ff-a1[i].ff);
      |                                     ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
/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:100:40: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
  100 |                                 ans=min(ans,a1[i+q-1].ff-a1[i].ff);
      |                                     ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
/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
/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:100:40: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
  100 |                                 ans=min(ans,a1[i+q-1].ff-a1[i].ff);
      |                                     ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~