Cod sursa(job #2969774)

Utilizator Zed1YasuoAlex Birsan Zed1Yasuo Data 23 ianuarie 2023 18:02:23
Problema Statistici de ordine Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.68 kb
#include <fstream>

using namespace std;
ifstream f("sdo.in");
ofstream g("sdo.out");
int n,k,a[3000005];
void qsort(int k, int st, int dr)
{
    int pivot = a[(st+dr)/2];
    int b = st, e = dr;
    while (a[b]<pivot)
        b++;

    while (a[e]>pivot)
        e--;
    while(b<e)
    {
        swap(a[b],a[e]);
        b++;
        while (a[b]<pivot)
            b++;
        e--;
        while (a[e]>pivot)
            e--;
    }

    if (st<e&&k<=e)
        qsort(k,st,e);
    else if (e + 1 < dr)
        qsort(k, e + 1, dr);
}

int main()
{
    f>>n>>k;
    for(int i=1;i<=n;i++)
        f>>a[i];
    qsort(k, 1, n);
    g<<a[k];
    return 0;
}