lina_os

Untitled

Mar 21st, 2025
15
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7. ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  8. int n, k;
  9. cin >> n >> k;
  10. map<int,int>m; //freq
  11. while (n--) {
  12. int x; cin >> x;
  13. m[x]++;
  14. }
  15. ll ans=0;
  16. for (auto [i,v] :m) {
  17. ans+=v;
  18. if (ans==k) {
  19. cout << i << endl;
  20. return 0;
  21. }
  22. if (ans>k) {
  23. cout << -1 << endl;
  24. return 0;
  25. }
  26. }
  27. if (ans==k) cout << 1000000000 << endl;
  28. else cout << -1 << endl;
  29. return 0;
  30. }
  31.  
  32. /*
  33. *
  34. *
  35. */
Advertisement
Add Comment
Please, Sign In to add comment