Source Code
#include<bits/stdc++.h>
using namespace std;

int main(){
    int n,k;
    cin>>n>>k;
    int a[n];
    for(int i= 0 ; i<n ; i++)
        cin>>a[i];
    sort(a,a+n);
    int ans = 0;
    for(int i= 0 ; i<k ; i++){
        if(i && a[i] == a[i-1])
            ans = a[i]+1;
        else
            ans = a[i];
    }
    cout<<ans<<endl;
}
Copy
Cutting Trees hashemtb
GNU G++17
69 ms
640 KB
Wrong Answer