Advertisement
esraa_syam

Untitled

Dec 7th, 2024
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.34 KB | None | 0 0
  1. #include "bits/stdc++.h"
  2. using namespace std;
  3.  
  4. #define nl "\n"
  5. #define ll long long
  6. #define mod  1'000'000'007
  7. #define all(v) v.begin(), v.end()
  8. #define rall(v) v.rbegin(), v.rend()
  9. #define sz(v) (int) v.size()
  10.  
  11. template<typename T = int>
  12. istream &operator>>(istream &in, vector<T> &v) {
  13.     for (auto &x: v) in >> x;
  14.     return in;
  15. }
  16.  
  17. template<typename T = int>
  18. ostream &operator<<(ostream &out, const vector<T> &v) {
  19.     for (const T &x: v) out << x << " ";
  20.     return out;
  21. }
  22.  
  23. void Sira() {
  24.     ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  25. #ifndef ONLINE_JUDGE
  26.     freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  27. #endif
  28. }
  29.  
  30. void solve() {
  31.     int n , k;
  32.     cin >> n >> k;
  33.  
  34.     map < ll  , int > mp;
  35.  
  36.     ll entry;
  37.     for (int i = 0; i < n; i++) {
  38.         cin >> entry;
  39.         mp[entry]++;
  40.     }
  41.  
  42.     if (k == 0) {
  43.         if (mp.begin() -> first == 1) {
  44.             cout << -1 << nl;
  45.         } else {
  46.             cout << 1 << nl;
  47.         }
  48.         return;
  49.     }
  50.  
  51.     int cnt = 0;
  52.  
  53.     for (auto &[f , s] : mp) {
  54.         cnt += s;
  55.         if (cnt == k) {
  56.             return void(cout << f << nl);
  57.         }
  58.     }
  59.     cout << -1 << nl;
  60.  
  61. }
  62.  
  63. int main() {
  64.     Sira();
  65.     int t = 1;
  66.     // cin >> t;
  67.     while (t--) {
  68.         solve();
  69.     }
  70.     return 0;
  71. }
  72.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement