Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define cin(v) for (auto &i : v) cin >> i;
- #define cout(v) for (auto &i : v) cout << i << " "; cout<<'\n';
- #define ll long long
- #define ull unsigned long long
- #define all(v) v.begin(), v.end()
- #define rall(v) v.rbegin(), v.rend()
- #define MOD 1000000007
- #define endl '\n'
- #define Time cerr << "Time Taken: " << (float)clock() / CLOCKS_PER_SEC << " Secs"<< "\n";
- void Warding()
- {
- ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
- #ifndef ONLINE_JUDGE
- freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
- #endif
- }
- /*
- STOP USING int
- */
- void solve(){
- ll n, k, x; cin>>n>>k;
- multiset<ll> mt;
- for(int i=0; i<n && cin>>x; i++){
- mt.insert(x);
- if(mt.size() == k) mt.erase(*prev(mt.end()));
- }
- if(!mt.size()) return void(cout<<-1<<endl);
- cout<<*prev(mt.end())<<endl;
- }
- int main()
- {
- Warding();
- int TC = 1;
- cin >> TC;
- while (TC--)
- {
- solve();
- }
- Time
- }
Advertisement
Add Comment
Please, Sign In to add comment