IMohammedNasr

F. Playing With Array

Sep 24th, 2022
692
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.04 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define cin(v) for (auto &i : v) cin >> i;
  4. #define cout(v) for (auto &i : v) cout << i << " "; cout<<'\n';
  5. #define ll long long
  6. #define ull unsigned long long
  7. #define all(v) v.begin(), v.end()
  8. #define rall(v) v.rbegin(), v.rend()
  9. #define MOD 1000000007
  10. #define endl '\n'
  11. #define Time cerr << "Time Taken: " << (float)clock() / CLOCKS_PER_SEC << " Secs"<< "\n";
  12.  
  13. void Warding()
  14. {
  15.     ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  16. #ifndef ONLINE_JUDGE
  17.     freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  18. #endif
  19. }
  20.  
  21. /*
  22. STOP USING int
  23. */
  24.  
  25.  
  26. void solve(){
  27.     ll n, k, x; cin>>n>>k;
  28.     multiset<ll> mt;
  29.     for(int i=0; i<n && cin>>x; i++){
  30.         mt.insert(x);
  31.         if(mt.size() == k) mt.erase(*prev(mt.end()));
  32.     }
  33.     if(!mt.size()) return void(cout<<-1<<endl);
  34.     cout<<*prev(mt.end())<<endl;
  35. }
  36.  
  37. int main()
  38. {
  39.     Warding();
  40.     int TC = 1;
  41.     cin >> TC;
  42.     while (TC--)
  43.     {
  44.         solve();
  45.     }
  46.     Time
  47. }
  48.  
  49.  
Advertisement
Add Comment
Please, Sign In to add comment