fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define du double
  5. #define endl '\n'
  6. #define IOS ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
  7.  
  8. int main() {
  9. IOS;
  10. int t;
  11. cin>>t;
  12. while(t--) {
  13. int n,m,k;
  14. cin>>n>>m>>k;
  15. vector<ll> v(n);
  16. for(int i=0;i<n;i++) {
  17. cin>>v[i];
  18. }
  19. multiset<ll> s;
  20.  
  21. vector <ll>ans;
  22. int cnt=0;
  23. for (int i = 0; i< n; i++) {
  24. cnt++;
  25. s.insert(v[i]);
  26. if(cnt==m){
  27. auto it=s.begin();
  28. ans.push_back(*it);
  29. s.erase(it);
  30. cnt--;
  31. }
  32.  
  33. }
  34. for (auto it:s) {
  35. ans.push_back(it);
  36. }
  37.  
  38. cout <<ans[k-1];
  39.  
  40.  
  41.  
  42. }
  43. return 0;
  44. }
Success #stdin #stdout 0s 5312KB
stdin
1
6 3 4
1 2 4 7 6 3
stdout
3