Untitled
#include <bits/stdc++.h> using namespace std ; #define ll long long #define For(n) for(long long i = 0; i < n; i++) #define endl '\n' #define int long long void solve () { int n,m,k; cin>>n>>m>>k; int arr[n];multiset<int> temp; vector<int>ans; For(n)cin>>arr[i]; For(m) temp.insert(arr[i]); for(int i =m;i<n;i++){ ans.push_back (*temp.begin()); temp.erase(temp.find(*temp.begin())); temp.insert(arr[i]); if(ans.size()>=k){ cout <<ans[k-1]<< endl; return; } } while(!temp.empty()){ ans.push_back(*temp.begin()); temp.erase(temp.find(*temp.begin())); if(ans.size()>=k){ cout << ans[k-1] << endl; return; } } cout << ans[k-1] << endl; } signed main () { ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); int t =1; cin>>t; while (t--){ solve(); } }
Leave a Comment