Source Code
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
#define ll long long

int main(){
    IOS
    int n,k;cin>>n>>k;
    vector<int>v(n);
    for(int i = 0;i<n;i++)
        cin>>v[i];

    sort(v.begin(),v.end());

    int ans=v[k-1];
    for(int i = k-1;i>0;i--)
        if(v[i]==v[i-1])
            ans++;
    cout<<ans;

}
Copy
Cutting Trees HusseinSaad
GNU G++17
16 ms
440 KB
Wrong Answer