Cod sursa(job #3326410)

Utilizator SkibidiCezarCezar Bolba SkibidiCezar Data 28 noiembrie 2025 19:09:44
Problema Statistici de ordine Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.7 kb
#include <bits/stdc++.h>
/// i love alex stan so much ///
/// i love alex stan so much ///
/// i love alex stan so much ///
/// i love alex stan so much ///
/// i love alex stan so much ///
/// i love alex stan so much ///
/// i love alex stan so much ///
/// i love alex stan so much ///
/// i love alex stan so much ///
/// i love alex stan so much ///
/// i love alex stan so much ///
/// i love alex stan so much ///
/// i love alex stan so much ///
/// i love alex stan so much ///
/*     /\           _____             _____ _______    /\     |\    |
      /  \    |     |       \  /     /         |      /  \    | \   |
     /----\   |     |--      \/      \_____    |     /----\   |  \  |
    /      \  |     |        /\            \   |    /      \  |   \ |
   /        \ |____ |____   /  \     ______/   |   /        \ |    \|   */

using namespace std;
ifstream fin ("algsort.in");
ofstream fout ("algsort.out");

int n, k;
int a[500005];
void merg(int l, int m, int r){
    int i = l;
    int j = m;
    vector <int> rez;
    while(i < m || j <= r){
        if((a[i] < a[j] && i < m) || j > r){
            rez.push_back(a[i]);
            i++;
        }
        else if(j <= r){
            rez.push_back(a[j]);
            j++;
        }
    }
    for(int i = 0; i < rez.size(); i++){
        a[l+i] = rez[i];
    }
}
void mergsort(int l, int r){
    //cout << l << " " << r << "\n";
    if(l < r){
        mergsort(l, (l + r) / 2);
        mergsort((l + r) / 2 + 1, r);
        merg(l, (l + r) / 2 + 1, r);
    }
}

int main()
{
    cin >> n >> k;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }
    mergsort(1, n);
    cout << a[k];
    return 0;
}