Source Code
#include "bits/stdc++.h"
 
using namespace std;
typedef long long ll;
 
void solve() {
    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];
    map<int, int> mp;
    for (int i = 0; i < k; i++) {
        if (++mp[v[i]] > 1) ans++;
     }

     cout << ans << '\n';
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    while (t--) {
        solve();
    }
}
Copy
Cutting Trees OsamaX01
GNU G++17
20 ms
1.5 MB
Wrong Answer