Problem:
L番目のK番目の数 (LthKthNumber)
問題文
横一列に並べられた
N
枚のカードがある．左から
i
枚目(
1 ≦ i ≦ N
)のカードには，整数
a_i
が書かれている．
JOI 君は，これらのカードを用いて次のようなゲームを行う．連続する
K
枚以上のカードの列を選び，次の操作を行う．
選んだカードを，書かれている整数が小さい順に左から並べる．
並べたカードのうち，左から
K
番目のカードに書かれた整数を紙に書き出す．
選んだカードを，すべて元の位置に戻す．
この操作を，連続する
K
枚以上のカードの列すべてに対して行う．すなわち，
1 ≦ l ≦ r ≦ N
かつ
K ≦ r - l + 1
を満たすすべての
(l,r)
について，
a_l, a_{l+1}, ..., a_r
のうち
K
番目に小さな整数を書き出す．
こうして書き出された整数を，左から小さい順に並べる．並べた整数のうち，左から
L
番目のものがこのゲームにおける JOI 君の得点である．JOI 君の得点を求めよ．
制約
1 \leq N \leq 200000
1 \leq K \leq N
1 \leq a_i \leq N
1 \leq L
JOI 君が書き出す整数は
L
個以上である．
入力・出力
入力
入力は以下の形式で標準入力から与えられる．
N
K
L
a_1
a_2
...
a_N
出力
JOI 君の得点を
1
行で出力せよ．
入出力例
入力例 1
4 3 2
4 3 1 2
出力例 1
3
1 \leq l \leq r \leq N (= 4)
かつ
K (= 3) \leq r - l + 1
を満たす
(l,r)
は，
(1,3), (1,4), (2,4)
の
3
通りある．
これらの
(l,r)
に対し，
a_l, a_{l+1}, ..., a_r
で
3
番目に小さな整数は，それぞれ
4, 3, 3
である．
このうち
L (= 2)
番目に小さい整数は
3
なので，JOI 君の得点は
3
である．同じ整数が複数あるときも，重複して数えることに注意せよ．
入力例 2
5 3 3
1 5 2 2 4
出力例 2
4
JOI 君が書き出す整数は，
(l,r) = (1,3)
に対し
5
(l,r) = (1,4)
に対し
2
(l,r) = (1,5)
に対し
2
(l,r) = (2,4)
に対し
5
(l,r) = (2,5)
に対し
4
(l,r) = (3,5)
に対し
4
である．このうち
L (= 3)
番目に小さい整数は
4
である．
入力例 3
6 2 9
1 5 3 4 2 4
出力例 3
4
入力例 4
6 2 8
1 5 3 4 2 4
出力例 4
3

Submitted solutions:

code_snippet: /* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>

#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>

#include <cmath>
#include <numeric>
#include <random>
#include <cstring>
#include <cassert>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <stack>

// type
#include <cstdint>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

int N, K, L;
int A[200005];

bool f(int x) {
    // x以下の数がK個以上ある連続区間の数を調べる
    int ret = 0;
    int cnt = 0;
    int r = -1;
    for (int l = 0; l < N; l++) {
        if (l >= 1 && A[l-1] <= x) cnt--;
        bool flag = false;

        while (r < 0 || cnt < K) {
            r++;
            if (A[r] <= x) cnt++;
            if (r >= N) {
                flag = true;
                break;
            }
        }

        if (flag) break;
        ret += N - r;
    }

    return ret >= L;
}

signed main() {
    cin >> N >> K >> L;
    for (int i = 0; i < N; i++) cin >> A[i];

    int lb = 0;
    int ub = INF;
    while (ub - lb > 1) {
        int mid = (ub + lb) / 2;
        if (f(mid)) {
            ub = mid;
        } else {
            lb = mid;
        }
    }

    cout << ub << endl;
}
accuracy: 1
time_ms: 50
memory_kb: 4928
final_rank: 6

code_snippet: #include <bits/stdc++.h>  // clang-format off
using namespace std;
using Int = long long;
#define REP2(i, n) for (Int i = 0, max_i = (n); i < max_i; i++)
#define REP3(i, a, b) for (Int i = (a), max_i = (b); i < max_i; i++)
#define OVERLOAD2(_1, _2, _3, name, ...) name
#define REP(...) OVERLOAD2(__VA_ARGS__, REP3, REP2)(__VA_ARGS__)
struct SetupIO { SetupIO() { cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(13); } } setup_io;
#ifndef _MY_DEBUG
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Tue Mar  3 15:58:12 JST 2020
 **/

signed main() {
    Int n, K, L;
    cin >> n >> K >> L;
    vector<Int> a(n);
    REP(i, n) cin >> a[i];
    // mid以下がL個以上あるかどうか
    vector<Int> acc(n + 1);
    auto check = [&](Int mid) -> bool {
        REP(i, n) { acc[i + 1] = acc[i] + (a[i] <= mid); }
        Int cnt = 0;
        REP(i, n) {
            cnt += acc.end() - lower_bound(acc.begin(), acc.end(), acc[i] + K);
        }
        return cnt >= L;
    };
    Int ok = 1e8, ng = 0;
    while (abs(ok - ng) > 1) {
        Int mid = (ok + ng) / 2;
        (check(mid) ? ok : ng) = mid;
    }
    cout << ok << endl;
}
accuracy: 1
time_ms: 160
memory_kb: 6244
final_rank: 16

code_snippet: #include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(...) 42
#endif

template <class T> bool ckmax(T &a, T b) { return a < b ? (a = b, true) : false; }
template <class T> bool ckmin(T &a, T b) { return a > b ? (a = b, true) : false; }

int64_t n, k, c;
const int MAXN = 2e5 + 5;
int pre[MAXN], a[MAXN];

/**

  Ta cnp ket qua. Dua ve bai toan kiem tra xem mot so x lon hon bao nhieu so trong day b
  Ta nhan thay, so x se nam trong day b khi va chi khi doan [l, r] co >= k so khong lon hon x
  Tim doan nho nhat thoa man, tat cac doan chua doan do deu se chua x

*/

bool check(int x) {
  for (int i = 1; i <= n; i++) pre[i] = pre[i - 1] + (a[i] <= x);
  int64_t r = 1, cnt = 0;
  for (int l = 1; l <= n; l++) {
    while (r < n && pre[r] - pre[l - 1] < k) r++;
    if (pre[r] - pre[l - 1] >= k) cnt += n - r + 1;
  }
//  debug(cnt);
  return cnt >= c;
}

int main() {
  #define NAME "test"
  if (fopen(NAME".inp", "r")) {
    freopen(NAME".inp", "r", stdin);
    freopen(NAME".out", "w", stdout);
  }
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n >> k >> c;
  for (int i = 1; i <= n; i++) cin >> a[i];
  int l = 1, r = n, ans;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (check(mid)) {
      r = mid - 1;
      ans = mid;
    } else {
      l = mid + 1;
    }
  }
  cout << ans << '\n';
  return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 5012
final_rank: 4

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

#define ll long long
#define ull unsigned long long
#define ld long double
#define pb push_back
#define mkp make_pair
#define fi first
#define se second
#define pii pair<int, int>
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)
#define per(i, l, r) for (int i = (r) - 1; i >= (l); --i)
#define INF 0x3f3f3f3f
#define LINF (ll)4e18
#define EPS 1e-9
#define PI acos(-1)
#define fopen_in(f) freopen(f, "r", stdin)
#define fopen_out(f) freopen(f, "w", stdout)
#define endl '\n'
#define debug(x) cerr << #x << ": " << x << endl
#define int ll
const int N = 2e5 + 5;
int n, k, c, a[N], b[N], pre[N];
bool check(int x)
{
    for (int i = 1; i <= n; i++)
    {
        pre[i] = pre[i - 1] + (a[i] <= x);
    }
    int r = 1, cnt = 0;
    for (int i = 1; i <= n; i++)
    {
        while (r <= n && pre[r] - pre[i - 1] < k)
            r++;
        if (pre[r] - pre[i - 1] >= k)
        cnt += n - r + 1;
    }
    return (cnt >= c);
}
void solve()
{
    cin >> n >> k >> c;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
    int l = 1, r = n, ans = -1;
    while (l <= r)
    {
        int mid = l + r >> 1;
        if (check(mid))
            ans = mid, r = mid - 1;
        else
            l = mid + 1;
    }
    cout << ans << endl;
}

main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int T = 1;
    // cin >> T;
    while (T--)
        solve();
    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 7544
final_rank: 10

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

#define ll long long
#define ull unsigned long long
#define ld long double
#define pb push_back
#define mkp make_pair
#define fi first
#define se second
#define pii pair<int, int>
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)
#define per(i, l, r) for (int i = (r) - 1; i >= (l); --i)
#define INF 0x3f3f3f3f
#define LINF (ll)4e18
#define EPS 1e-9
#define PI acos(-1)
#define fopen_in(f) freopen(f, "r", stdin)
#define fopen_out(f) freopen(f, "w", stdout)
#define endl '\n'
#define debug(x) cerr << #x << ": " << x << endl

const int N = 2e5 + 5;
int n, k, c, a[N], b[N], pre[N];
bool check(int x)
{
    for (int i = 1; i <= n; i++)
    {
        pre[i] = pre[i - 1] + (a[i] <= x);
    }
    int r = 1, cnt = 0;
    for (int i = 1; i <= n; i++)
    {
        while (r <= n && pre[r] - pre[i - 1] < k)
            r++;
        if (pre[r] - pre[i - 1] >= k)
        cnt += n - r + 1;
    }
    return (cnt >= c);
}
void solve()
{
    cin >> n >> k >> c;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
    int l = 1, r = n, ans = -1;
    while (l <= r)
    {
        int mid = l + r >> 1;
        if (check(mid))
            ans = mid, r = mid - 1;
        else
            l = mid + 1;
    }
    cout << ans << endl;
}

main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int T = 1;
    // cin >> T;
    while (T--)
        solve();
    return 0;
}
accuracy: 0.7027027027027027
time_ms: 10
memory_kb: 4072
final_rank: 19

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

#define ll long long
#define ull unsigned long long
#define ld long double
#define pb push_back
#define mkp make_pair
#define fi first
#define se second
#define pii pair<int, int>
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)
#define per(i, l, r) for (int i = (r) - 1; i >= (l); --i)
#define INF 0x3f3f3f3f
#define LINF (ll)4e18
#define EPS 1e-9
#define PI acos(-1)
#define fopen_in(f) freopen(f, "r", stdin)
#define fopen_out(f) freopen(f, "w", stdout)
#define endl '\n'
#define debug(x) cerr << #x << ": " << x << endl

const int N = 2e5 + 5;
int n, k, c, a[N], b[N], pre[N];
bool check(int x)
{
    for (int i = 1; i <= n; i++)
    {
        pre[i] = pre[i - 1] + (a[i] <= x);
    }
    int r = 1, cnt = 0;
    for (int i = 1; i <= n; i++)
    {
        while (r <= n && pre[r] - pre[i - 1] < k)
            r++;
        if (r > n)
            break;
        cnt += n - r + 1;
    }
    return (cnt >= c);
}
void solve()
{
    cin >> n >> k >> c;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
    int l = 1, r = n, ans = -1;
    while (l <= r)
    {
        int mid = l + r >> 1;
        if (check(mid))
            ans = mid, r = mid - 1;
        else
            l = mid + 1;
    }
    cout << ans << endl;
}

main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int T = 1;
    // cin >> T;
    while (T--)
        solve();
    return 0;
}
accuracy: 0.7027027027027027
time_ms: 10
memory_kb: 3900
final_rank: 18

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define int long long
const int maxn = 2e5 + 5;
int n, k, l, a[maxn], sum[maxn];
bool check (int x) {
    int cnt = 0;
    for (int i = 1; i <= n; i++)
        sum[i] = sum[i - 1] + (a[i] <= x);
    for (int i = 1, j = 1; i <= n; i++) {
        while (j < n && sum[j] - sum[i - 1] < k)
            j++;
        if (sum[j] - sum[i - 1] >= k) cnt += n - j + 1;
    }
    return cnt >= l;
}
signed main () {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> k >> l;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    int l = 1, r = n, mid, ans;
    while (l <= r) {
        mid = l + r >> 1;
        if (check (mid)) {
            ans = mid;
            r = mid - 1;
        }
        else l = mid + 1;
    }
    cout << ans << '\n';
}
accuracy: 1
time_ms: 20
memory_kb: 6588
final_rank: 8

code_snippet: #include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(A) A.begin(),A.end()


void solve(){
    ll N,K,L;
    cin>>N>>K>>L;
    vector<ll> A(N);
    rep(i,N)cin>>A[i];
    ll ok=0,ng=N+1;
    while(ng-ok>1){
        ll mid=(ok+ng)/2;
        vector<ll> B(N+1,0);
        rep(i,N){
            B[i+1]=B[i]+(A[i]<=mid);
        }
        ll cnt=0;
        rep(i,N){
            ll p=lower_bound(all(B),B[i]+K)-B.begin();
            p=max(p,i+K);
            p=min(p,N+1);
            if(p>=0)cnt+=N+1-p;
        }
        (cnt<L?ok:ng)=mid;
    }
    cout<<ng<<endl;
}

int main(){
    
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int T=1;
    while(T--)
    solve();
}
accuracy: 1
time_ms: 80
memory_kb: 6216
final_rank: 11

code_snippet: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pi;
typedef pair<ll,pi> ppi;
typedef pair<ll,ppi> pppi;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
#define FOR(i,l,r) for(ll i=l;i<r;i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(A) A.begin(),A.end()
#define LB(A,x) (lower_bound(ALL(A),x)-A.begin())
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return 1;}return 0;}
int main(){
    ll N,K,L;cin>>N>>K>>L;
    vi A(N);REP(i,N)cin>>A[i];
    ll l=0,r=N+1;
    while(r-l>1){
        ll m=(l+r)/2;
        vector<ll>B;
        REP(i,N)if(A[i]<=m)B.emplace_back(i);
        ll cnt=0;
        REP(i,N){
            ll t=LB(B,i);
            if(t+K>B.size())break;
            cnt+=N-B[t+K-1];
        }
        if(cnt>=L)r=m;
        else l=m;
    }
    cout<<r<<endl;
    return 0;
}
accuracy: 1
time_ms: 110
memory_kb: 8336
final_rank: 17

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll=int64_t;

struct bit{
  vector<int> b;
  int m,m2;
  
  bit(int n){
    m=n;
    m2=1;
    while(m2<n) m2*=2;
    m2/=2;
    b.resize(m+1,0);
  }
  
  void add(int a,int w){
    for(int x=a;x<=m;x+=x&-x) b[x]+=w;
  }
  
  int sum(int a){
    int res=0;
    for(int x=a;x>0;x-=x&-x) res+=b[x];
    return res;
  }
  
  int lb(int w){
    int x=0;
    for(int k=m2;k>0;k/=2){
      if(k+x<=m && b[k+x]<w){
        w-=b[k+x];
        x+=k;
      }
    }
    return x+1;
  }
  
};

int main() {
  int n,k;
  ll l;
  cin >> n >> k >> l;

  vector<int> a(n);
  int amx=0;
  for(int i=0;i<n;i++){
    cin >> a[i];
    amx=max(amx,a[i]);
  }
  
  
  int s=0,t=amx;
  while(t-s>1){
    int md=(s+t)/2;
    int rgt=0;
    ll num=0;
    bit bt(amx);
    for(int lft=0;lft<n;lft++){
      while(rgt<n && bt.sum(md)<k){
        bt.add(a[rgt],1);
        rgt++;
      }
      if(bt.sum(md)<k) break;
      num+=n-rgt+1;
      bt.add(a[lft],-1);
    }
    if(num>=l) t=md;
    else s=md;
  }
  cout << t << endl;
}
accuracy: 1
time_ms: 140
memory_kb: 4696
final_rank: 13

code_snippet: #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) { return (ull)rng() % B; }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, k;
    cin >> n >> k;
    ll L;
    cin >> L;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    auto check = [&](int x) -> bool {
        int cnt = 0;
        ll sum = 0;
        int r = 0;
        for (int i = 0; i < n; ++i) {
            while (r < n and cnt < k) {
                if (a[r] <= x) cnt += 1;
                r += 1;
            }
            if (cnt >= k) sum += n - r + 1;
            if (a[i] <= x) cnt -= 1;
        }
        return sum >= L;
    };
    int l = 0, r = n;
    while (r - l > 1) {
        int mid = (l + r) / 2;
        if (check(mid)) r = mid;
        else l = mid;
    }
    cout << r << endl;
}
accuracy: 1
time_ms: 20
memory_kb: 3900
final_rank: 1

code_snippet: #include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5+7;
using ll = long long;
int n,k; ll l;
int A[maxn];

bool check(int x)
{
	int cnt=0,tot=0,r=1;
	for(int i=1;i<=n;i++)
	{
		while(r<=n && cnt<k)
		{
			if(A[r]<=x)++cnt;
			++r;
		}
		if(cnt==k)tot+=n-r+2;
		if(A[i]<=x)--cnt;
	}
	
	return tot>=l;
}

int main()
{
	cin>>n>>k>>l;
	for(int i=1;i<=n;i++)cin>>A[i];
	
	int ok=2e5,no=0;
	while(no+1<ok)
	{
		int mid = (ok+no)/2;
		if(check(mid))ok=mid;
		else no=mid;
	}
	cout<<ok<<endl;
	
	return 0;
}
accuracy: 0.7027027027027027
time_ms: 40
memory_kb: 4120
final_rank: 20

code_snippet: #include<bits/stdc++.h>
using namespace std;
int main(){
    int n, k, a[200010];
    long long l;
    cin >> n >> k >> l;
    for(int i=0;i<n;i++) cin >> a[i];
    int le=1, ri=n;
    while(le < ri){
        int mid = (le+ri)/2;
        int j=0, cnt=0;
        long long sum=0;
        for(int i=0;i<n;i++){
            while(j<n && cnt<k){
                if(a[j]<=mid) cnt++;
                j++;
            }
            if(cnt==k) sum += (n-j+1);
            if(a[i]<=mid) cnt--;
        }
        if(sum>=l) ri = mid;
        else le = mid+1;
    }
    cout << ri << endl;
    return(0);
}
accuracy: 1
time_ms: 50
memory_kb: 3848
final_rank: 3

code_snippet: #include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define int ll
#define rep(i, n) for(int i = 1; i <= n; ++i)
#define forn(i, l, r) for(int i = l; i <= r; ++i)
#define ford(i, r, l) for(int i = r; i >= l; --i)
#define FOR(i, n) for(int i = 0; i < n; ++i)
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define task "MEETING"
#define endl "\n"
#define sz(a) int(a.size())
#define C(x, y) make_pair(x, y)
#define all(a) (a).begin(), (a).end()
#define bit(i, mask) (mask >> i & 1)

template<typename T> bool maximize(T &res, const T &val) { if (res <= val){ res = val; return true; }; return false; }
template<typename T> bool minimize(T &res, const T &val) { if (res >= val){ res = val; return true; }; return false; }


const int N =  2e5 + 2;
const int K = 1e3 + 1;
const int MOD = 1e9 + 7;
const int INF = 500;
const int block_size = 230;
const int offset = 118;
const int LIM = 250;
const int AL = 26;
const int M = 11;
const int LOG = 20;

int n, k, l;

int a[N];

vector<int> c;

bool check(int x)
{
	int j = 1, cnt = 0, res = 0;
	rep(i, n)
	{
		while(j <= n && cnt < k) cnt += a[j] <= x, ++j;
		if(cnt == k) res += n - j + 2;
		cnt -= a[i] <= x;
	}
	return res >= l;
}

void solve()
{
    cin >> n >> k >> l;
	rep(i, n) cin >> a[i], c.pb(a[i]);
	sort(all(c));

	int l = 1, r = n, res = 0;
	while(l <= r)
	{
		int mid = l + r >> 1;
		if(check(c[mid - 1])) res = mid, r = mid - 1;
		else l = mid + 1;
	}
	cout << c[res - 1];
}

signed main()
{

    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    if(fopen(task".inp", "r"))
    {
        freopen(task".inp", "r", stdin);
        freopen(task".out", "w", stdout);
    }

	int TC = 1;
    while(TC--)
    {
        solve();
        cout << endl;
    }

    return 0;
}
//haha
accuracy: 1
time_ms: 30
memory_kb: 6456
final_rank: 9

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using pl = pair<ll,ll>;
using vp = vector<pl>;
#define rep(i,n) for(ll i=0;i<(ll)(n);++i)
#define reps(i,s,n) for(ll i=(s);i<(ll)(n);++i)
#define rep1(i,n) for(ll i=1;i<=(ll)(n);++i)
template<typename T>inline bool chmax(T &a,T b){return a<b?a=b,true:false;}
template<typename T>inline bool chmin(T &a,T b){return a>b?a=b,true:false;}
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define be(v) (v).begin(),(v).end()
const long long INF = 1e18;
#ifdef DEBUG
#include <debug.hpp>
random_device rd;
mt19937 gen(rd());
ll random(ll l,ll h){
	uniform_int_distribution<ll> dist(l,h);
	return dist(gen);
}
#endif

ll N,K,L;
vp A;
void input(){
	cin>>N>>K>>L;
	A.assign(N,pl(0,0));
	rep(n,N){
		cin>>A.at(n).fi;
		A.at(n).se = n;
	}
}
#ifdef DEBUG
void showall(){
	show(N,K,L,A);
}
#endif
ll logic(){
	sort(be(A));
	vl ind(N);
	rep(n,N){
		ind.at(A.at(n).se) = n;
	}
	#ifdef DEBUG
	show("ind",ind);
	#endif
	ll ng=0,ok=N;
	while(ng < ok - 1){
		ll m=(ok+ng)/2;
		#ifdef DEBUG
		show("ng ok m",ng,ok,m);
		#endif
		ll sum=0,cnt=0,r=-1;
		rep(l,N){
			#ifdef DEBUG
			show(" l r cnt",l,r,cnt);
			#endif
			while(r<N && cnt < K){
				++r;
				if(r<N && ind.at(r) <= m){
					++cnt;
				}
			}
			sum += N - r;
	#ifdef DEBUG
			show("   r,cnt,sum",r,cnt,sum);
	#endif
			if(ind.at(l) <= m)--cnt;
	#ifdef DEBUG
			show("   cnt",cnt);
	#endif
		}
		if(sum>=L)ok=m;
		else ng=m;
	#ifdef DEBUG
		show(" sum,sum>=L,ng,ok",sum,(sum>=L),ng,ok);
	#endif
	}
	return A.at(ok).fi;
}
#ifdef DEBUG
ll naive(){
	return 1;
}
#endif
int main(){
	#ifdef DEBUG
	cout << "--- Input ---" << endl;
	#endif
	input();
	#ifdef DEBUG
	showall();
	cout << "--- Logic ---" << endl;
	#endif
	ll ans=logic();
	#ifdef DEBUG
	cout << "--- Answer ---" << endl;
	#endif
	cout<<ans<<endl;
	//while(input())logic();
	#ifdef DEBUG
	//show("naive=",naive());
	#endif
	#ifdef DEBUG
	/*
	rep(q,100){
		N=random(1LL,1000LL);
		ll lans=logic(),nans=naive();
		showall();
		if(lans!=nans){ show(" WA",lans,nans); break; }
		else{ show(" AC",lans,nans); }
	}
	*/
	#endif
	return 0;
}
//cout << fixed << setprecision(9);
accuracy: 1
time_ms: 60
memory_kb: 7796
final_rank: 15

code_snippet: /*
勉強させていただいた記事
https://qiita.com/drken/items/ecd1a472d3a0e7db8dce#%E5%95%8F%E9%A1%8C-9joi-2017-%E4%BA%88%E9%81%B8-f-l%E7%95%AA%E7%9B%AE%E3%81%AEk%E7%95%AA%E7%9B%AE%E3%81%AE%E6%95%B0
https://algo-logic.info/binary-indexed-tree/#

*/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;

const ll LongINF=1e13+7;
const int INF=1e9+7;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template <class T, class Y>T GCD(T a, Y b){if(a<b){T c=a;a=b;b=c;}if (a % b == 0){return b;}return GCD(b, a % b);}
template<class T,class Y>T LCM(T a,Y b){return (a*b)/GCD(a,b);}
void clear(queue<pair<int, int>> &q){queue<pair<int, int>> empty;swap(q, empty);} //queueの中身の型は適時変更を忘れない

using vi=vector<int>;
using vii=vector<vi>;

#define REP(i,a,b) for(ll i=(a);i<(b);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define rv reverse
#define ALL(a) (a).begin(),(a).end()
#define decimal(x) fixed<<setprecision(x)

template <class Abel> struct BIT{
    vector<Abel> dat;
    Abel UNITY_SUM=0;

    BIT(int n){
        init(n);
    }

    //1-indexed
    //配列数nを確保
    void init(int n){
        dat.resize(n+1);
        rep(i,dat.size())dat[i]=UNITY_SUM;
    }


    //加算のやり方として i+=i&-iと、bitが立っている最下位を加算することで、変更の必要があるものを指すことができる。
    inline void add(int a,Abel x){
        for(int i=a;i<(int)dat.size();i += i & -i){
            dat[i]=dat[i]+x;
        }
    }

    //inline を使うことで使い分けができる。
    ////減算のやり方として i-=i&-iと、bitが立っている最下位を減算することで、変更の必要があるものを指すことができる。
    inline Abel sum(int a){
        Abel res=UNITY_SUM;
        for(int i=a;i>0;i-=i&-i){
            res=res+dat[i];
        }
        return res;
    }

    inline Abel sum(int a,int b){
        return sum(b-1)-sum(a-1);
    }
};

int main(){
    ll N,K,L;
    cin>>N>>K>>L;
    vi a(N);
    rep(i,N)cin>>a[i];
    
    int low=0,high=N;
    while(high-low>1){
        int mid=low+(high-low)/2;

        BIT<int> bit(N+1);
        int right=0;
        ll num=0;
        rep(left,N){
            while(right<N&&bit.sum(mid)<K){
                bit.add(a[right],1);
                right++;
            }
            if(bit.sum(mid)<K)break;
            num+=N-right+1;
            bit.add(a[left],-1);
        }

        if(num>=L)high=mid;
        else low=mid;
    }

    cout<<high<<endl;

    return 0;
}
/*

*/
accuracy: 1
time_ms: 150
memory_kb: 4660
final_rank: 14

code_snippet: //#define _GLIBCXX_DEBUG

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

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define UNIQUE(a) (a).erase(unique((a).begin(),(a).end()),(a).end())
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (ll)(m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD1 = 1e9+7;
const ll MOD9 = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T> using PQ = priority_queue<T>;
template<typename T> using QP = priority_queue<T,vector<T>,greater<T>>;
template<typename T1, typename T2>bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
template<typename T1, typename T2>bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T1,typename T2,typename T3>void anss(T1 x,T2 y,T3 z){ans(x!=y,x,z);};  
template<typename T>void debug(const T &v,ll h,ll w,string sv=" "){for(ll i=0;i<h;i++){cout<<v[i][0];for(ll j=1;j<w;j++)cout<<sv<<v[i][j];cout<<endl;}};
template<typename T>void debug(const T &v,ll n,string sv=" "){if(n!=0)cout<<v[0];for(ll i=1;i<n;i++)cout<<sv<<v[i];cout<<endl;};
template<typename T>void debug(const vector<T>&v){debug(v,v.size());}
template<typename T>void debug(const vector<vector<T>>&v){for(auto &vv:v)debug(vv,vv.size());}
template<typename T>void debug(stack<T> st){while(!st.empty()){cout<<st.top()<<" ";st.pop();}cout<<endl;}
template<typename T>void debug(queue<T> st){while(!st.empty()){cout<<st.front()<<" ";st.pop();}cout<<endl;}
template<typename T>void debug(deque<T> st){while(!st.empty()){cout<<st.front()<<" ";st.pop_front();}cout<<endl;}
template<typename T>void debug(PQ<T> st){while(!st.empty()){cout<<st.top()<<" ";st.pop();}cout<<endl;}
template<typename T>void debug(QP<T> st){while(!st.empty()){cout<<st.top()<<" ";st.pop();}cout<<endl;}
template<typename T>void debug(const set<T>&v){for(auto z:v)cout<<z<<" ";cout<<endl;}
template<typename T>void debug(const multiset<T>&v){for(auto z:v)cout<<z<<" ";cout<<endl;}
template<typename T,size_t size>void debug(const array<T, size> &a){for(auto z:a)cout<<z<<" ";cout<<endl;}
template<typename T,typename V>void debug(const map<T,V>&v){for(auto z:v)cout<<"["<<z.first<<"]="<<z.second<<",";cout<<endl;}
template<typename T>vector<vector<T>>vec(ll x, ll y, T w){vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,-1,0,0,1,1,-1,-1};vector<ll>dy={0,0,1,-1,1,-1,1,-1};
template<typename T>vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v(ts...))>(a,make_v(ts...));}
template<typename T1, typename T2>ostream &operator<<(ostream &os, const pair<T1, T2>&p){return os << p.first << " " << p.second;}
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v){for(auto &z:v)os << z << " ";cout<<"|"; return os;}
template<typename T>void rearrange(vector<int>&ord, vector<T>&v){
  auto tmp = v;
  for(int i=0;i<tmp.size();i++)v[i] = tmp[ord[i]];
}
template<typename Head, typename... Tail>void rearrange(vector<int>&ord,Head&& head, Tail&&... tail){
  rearrange(ord, head);
  rearrange(ord, tail...);
}
template<typename T> vector<int> ascend(const vector<T>&v){
  vector<int>ord(v.size());iota(ord.begin(),ord.end(),0);
  sort(ord.begin(),ord.end(),[&](int i,int j){return make_pair(v[i],i)<make_pair(v[j],j);});
  return ord;
}
template<typename T> vector<int> descend(const vector<T>&v){
  vector<int>ord(v.size());iota(ord.begin(),ord.end(),0);
  sort(ord.begin(),ord.end(),[&](int i,int j){return make_pair(v[i],-i)>make_pair(v[j],-j);});
  return ord;
}
template<typename T> vector<T> inv_perm(const vector<T>&ord){
  vector<T>inv(ord.size());
  for(int i=0;i<ord.size();i++)inv[ord[i]] = i;
  return inv;
}
ll FLOOR(ll n,ll div){assert(div>0);return n>=0?n/div:(n-div+1)/div;}
ll CEIL(ll n,ll div){assert(div>0);return n>=0?(n+div-1)/div:n/div;}
ll digitsum(ll n){ll ret=0;while(n){ret+=n%10;n/=10;}return ret;}
ll modulo(ll n,ll d){return (n%d+d)%d;};
template<typename T>T min(const vector<T>&v){return *min_element(v.begin(),v.end());}
template<typename T>T max(const vector<T>&v){return *max_element(v.begin(),v.end());}
template<typename T>T acc(const vector<T>&v){return accumulate(v.begin(),v.end(),T(0));};
template<typename T>T reverse(const T &v){return T(v.rbegin(),v.rend());};
//mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());
int popcount(ll x){return __builtin_popcountll(x);};
int poplow(ll x){return __builtin_ctzll(x);};
int pophigh(ll x){return 63 - __builtin_clzll(x);};
template<typename T>T poll(queue<T> &q){auto ret=q.front();q.pop();return ret;};
template<typename T>T poll(priority_queue<T> &q){auto ret=q.top();q.pop();return ret;};
template<typename T>T poll(QP<T> &q){auto ret=q.top();q.pop();return ret;};
template<typename T>T poll(stack<T> &s){auto ret=s.top();s.pop();return ret;};
ll MULT(ll x,ll y){if(LLONG_MAX/x<=y)return LLONG_MAX;return x*y;}
ll POW2(ll x, ll k){ll ret=1,mul=x;while(k){if(mul==LLONG_MAX)return LLONG_MAX;if(k&1)ret=MULT(ret,mul);mul=MULT(mul,mul);k>>=1;}return ret;}
ll POW(ll x, ll k){ll ret=1;for(int i=0;i<k;i++){if(LLONG_MAX/x<=ret)return LLONG_MAX;ret*=x;}return ret;}
template< typename T = int >
struct edge {
  int to;
  T cost;
  int id;
  edge():id(-1){};
  edge(int to, T cost = 1, int id = -1):to(to), cost(cost), id(id){}
  operator int() const { return to; }
};

template<typename T>
using Graph = vector<vector<edge<T>>>;
template<typename T>
Graph<T>revgraph(const Graph<T> &g){
  Graph<T>ret(g.size());
  for(int i=0;i<g.size();i++){
    for(auto e:g[i]){
      int to = e.to;
      e.to = i;
      ret[to].push_back(e);
    }
  }
  return ret;
}
template<typename T>
Graph<T> readGraph(int n,int m,int indexed=1,bool directed=false,bool weighted=false){
  Graph<T> ret(n);
  for(int es = 0; es < m; es++){
    int u,v;
    T w=1;
    cin>>u>>v;u-=indexed,v-=indexed;
    if(weighted)cin>>w;
    ret[u].emplace_back(v,w,es);
    if(!directed)ret[v].emplace_back(u,w,es);
  }
  return ret;
}
template<typename T>
Graph<T> readParent(int n,int indexed=1,bool directed=true){
  Graph<T>ret(n);
  for(int i=1;i<n;i++){
    int p;cin>>p;
    p-=indexed;
    ret[p].emplace_back(i);
    if(!directed)ret[i].emplace_back(p);
  }
  return ret;
}
template<typename T>
struct BIT{
  ll n;
  ll k=1;
  vector<T>data;
  BIT() = default;
  BIT(ll size):n(size){
    data.assign(n,0);
    while(k*2<=n)k*=2;
  }
  void add(ll a,T w){
    for(ll i=a+1;i<=n;i+=i&-i)data[i-1]+=w;
  }
  T sum(ll a){//[0,a)
	  if(a<=0)return 0;
    T ret = 0;
    for(ll i=a;i>0;i-=i&-i)ret+=data[i-1];
    return ret;
  }
  //[a,b)
  T sum(ll a,ll b){return a>=b?0:sum(b)-sum(a);}
  T operator[](ll pos){
    return sum(pos,pos+1);
  }
  ll lower_bound(ll x){
    ll ret=0;    
    for(ll i=k;i>0;i/=2){
      if(ret+i<=n&&data[ret+i-1]<x){
        x-=data[ret+i-1];
        ret+=i;
      }
    }
    return ret;
  }
  ll lower_first(ll x){
    return lower_bound(sum(n)-x+1);
  }
  void print(){
    for(ll i=0;i<n;i++){
      if(i!=0)cout<<" ";
      cout<<(*this)[i];
    }
    cout<<endl;
  }
};
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
	ll n,k,l;cin>>n>>k>>l;
	vector<ll>a(n);
	rep(i,0,n)cin>>a[i];
	ll ok=1,ng=n+1;
	while(ng-ok>=2){
		ll mid=(ok+ng)/2;
		queue<ll>que;
		ll cnt=0;
		ll num=0;
		rep(i,0,n){
			if(a[i]<mid)que.push(i);
			while(que.size()>k)que.pop();
			ll f=0;
			if(que.size()==k)f=que.front()+1;
			cnt+=max(0LL,i+1-f-(k-1));
			//cout<<"c" spa i spa cnt<<endl;
			num+=max(0LL,i+1-(k-1));
		}
		//cout<<mid spa cnt<<endl;
		if(num-cnt<l)ok=mid;
		else ng=mid;
	}
	cout<<ok<<endl;
  return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 6120
final_rank: 7

code_snippet: /* [Author : Hoang Duy Vu] - THPT Chuyen Nguyen Du    */
#include <bits/stdc++.h>
#define All(x) (x).begin(),(x).end()
#define ll long long
#define C make_pair
#define fi first
#define se second
#define two second.first
#define thr second.second
#define TASK "txt"
using namespace std;
template<typename T> bool maximize(T &res, const T &val) {
    if (res < val) { res = val; return true; } return false; }
template<typename T> bool minimize(T &res, const T &val) {
    if (res > val) { res = val; return true; } return false; }

typedef pair<int,int> ii;
typedef pair<int,ii> iii;
const int LOG = 20;
const int INF = 1e9 + 7;
const ll LNF = 1e18 + 7;
const int mod = 1e9 + 7;
const int N = 2e5 + 100;

ll f[N] = {0};
int a[N];
int n , k;
ll l;

void input()
{
    cin >> n >> k >> l;

    for (int i = 1 ; i <= n ; i++) cin >> a[i];
}

bool ok(int h)
{
    int pre = 0;
    f[0] = 0;
    ll cnt = 0;

    for (int i = 1 ; i <= n ; i++) 
    {
        pre += (a[i] <= h);
        f[pre] = i;

        if (pre >= k)
        cnt += f[pre - k] + 1ll;
    }

    return cnt >= l;     
}

void solve()
{
    int l = 1 , r = n , res = 0;

    while (l <= r)
    {
        int m = (l + r) >> 1;

        if (ok(m)) 
        {
            res = m;
            r = m - 1;
        }
        else l = m + 1;
    }

    cout << res << '\n';
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL); cout.tie(NULL);
    if(fopen(TASK".inp", "r")){
    freopen(TASK".inp","r",stdin);
    freopen(TASK".out","w",stdout);
    }

    int tk;
    tk = 1;
   //cin >> tk;
    while (tk--)
    {
        input();
        solve();
    }
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 5596
final_rank: 5

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;

template <class T> struct fenwick_tree {
    using U = T;

  public:
    fenwick_tree() : _n(0) {}
    fenwick_tree(int n) : _n(n), data(n) {}

    void add(int p, T x) {
        assert(0 <= p && p < _n);
        p++;
        while (p <= _n) {
            data[p - 1] += U(x);
            p += p & -p;
        }
    }

    T sum(int l, int r) {
        assert(0 <= l && l <= r && r <= _n);
        return sum(r) - sum(l);
    }

  private:
    int _n;
    std::vector<U> data;

    U sum(int r) {
        U s = 0;
        while (r > 0) {
            s += data[r - 1];
            r -= r & -r;
        }
        return s;
    }
};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    ll L;
    cin >> n >> k >> L;
    vector<int> a(n);
    for(auto &&v:a)cin >> v;
    a.push_back(0);
    int ok = 1, ng = n + 1;
    while(ok + 1 < ng){
        int mid = (ok + ng) / 2;
        ll cnt = 0;
        fenwick_tree<int> fw(n + 1);
        for(int l = 0, r = 0; l < n; l++){
            while(r <= n && fw.sum(0, mid + 1) < k)fw.add(a[r++], 1);
            cnt += n + 1 - r;
            fw.add(a[l], -1);
        }
        if(cnt < L)ok = mid;
        else ng = mid;
    }
    cout << ++ok << '\n';
}
accuracy: 1
time_ms: 140
memory_kb: 4552
final_rank: 12

code_snippet: #include <bits/stdc++.h>
	using namespace std;
	
	void file() {
		const string LTM = "";
		if (fopen((LTM + ".inp").c_str(), "r")) {
			freopen((LTM + ".inp").c_str(), "r", stdin);
			freopen((LTM + ".out").c_str(), "w", stdout);
		}	
	}
	
	const int N = 2e5 + 5;
	
	int n, k, a[N];
	long long l;
	
	bool check(int x) {
		long long cnt = 0;
		for (int i = 1, j = 1, s = 0; i <= n; ++i) {
			while (s < k && j <= n) {
				if (a[j] <= x) ++s; ++j;
			} 
			if (s == k) cnt += n - j + 2;
			if (a[i] <= x) --s;
		}
		return cnt >= l;
	}
	
	int main() {
		cin.tie(0)->sync_with_stdio(0); 
		cin >> n >> k >> l;
		for (int i = 1; i <= n; ++i) cin >> a[i];
		int lo = 1, hi = n, res;
		while (lo <= hi) {
			int mi = (lo + hi) / 2;
			if (check(mi)) res = mi, hi = mi - 1;
			else lo = mi + 1;
		}
		cout << res << '\n';
		return 0;
	}
accuracy: 1
time_ms: 30
memory_kb: 4140
final_rank: 2