Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "bits/stdc++.h"
- using namespace std;
- #define nl "\n"
- #define ll long long
- #define mod 1'000'000'007
- #define all(v) v.begin(), v.end()
- #define rall(v) v.rbegin(), v.rend()
- #define sz(v) (int) v.size()
- template<typename T = int>
- istream &operator>>(istream &in, vector<T> &v) {
- for (auto &x: v) in >> x;
- return in;
- }
- template<typename T = int>
- ostream &operator<<(ostream &out, const vector<T> &v) {
- for (const T &x: v) out << x << " ";
- return out;
- }
- void Sira() {
- 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
- }
- void solve() {
- int n , k;
- cin >> n >> k;
- map < ll , int > mp;
- ll entry;
- for (int i = 0; i < n; i++) {
- cin >> entry;
- mp[entry]++;
- }
- if (k == 0) {
- if (mp.begin() -> first == 1) {
- cout << -1 << nl;
- } else {
- cout << 1 << nl;
- }
- return;
- }
- int cnt = 0;
- for (auto &[f , s] : mp) {
- cnt += s;
- if (cnt == k) {
- return void(cout << f << nl);
- }
- }
- cout << -1 << nl;
- }
- int main() {
- Sira();
- int t = 1;
- // cin >> t;
- while (t--) {
- solve();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement