Source Code
#include<bits/stdc++.h>
using namespace std;
int main(){
    int k, n, s, counter = 0;
    cin >> n >> k;
    vector<int> v;
    for(int i = 0; i < n; i++){
        cin >> s;
        v.push_back(s);
    }
    sort(v.begin(), v.end());
    for(int i =1; i < n; i++){
        if(v[i] == v[i-1])
        counter++;
    }
    cout << v[k-1] + counter -1;
}
Copy
Cutting Trees Oj3far
GNU G++17
1 ms
184 KB
Wrong Answer