专栏

题意


思路












Code:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll read(){
    ll x, f = 1;
    char ch;
    while(ch = getchar(), ch < '0' || ch > '9') if(ch == '-') f = -1;
    x = ch - '0';
    while(ch = getchar(), ch >= '0' && ch <= '9') x = x * 10 + ch - 48;
    return x * f;
}
int a[250005],s[250005],n,k;
ll m;
bool check(int x) {
    int l=0; ll sum=0;
    for(int i=1;i<=n;++i) s[i]=s[i-1]+(a[i]>=x);
    for(int i=k;i<=n;++i) {
        while(s[i]-s[l]==k) ++l;
        sum+=l;
    }
    if(sum>=m) return true;
    else return false;//x偏大 
}
int main() {
    int t=read();
    while(t--) {
        n=read(),k=read(),m=read();
        for(int i=1;i<=n;++i) a[i]=read();
        int l=1,r=1e9;
        while(l<=r) {
            int mid=(l+r)>>1;
            if(!check(mid)) r=mid-1;
            else l=mid+1;
        }
        printf("%d\n",r);
    }
    return 0;
}