Cod sursa(job #3327876)

Utilizator vladinfo_Grecu Vlad vladinfo_ Data 5 decembrie 2025 16:07:13
Problema Statistici de ordine Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.91 kb
#include <bits/stdc++.h>
/// Template Dutzu
#define fast ios_base::sync_with_stdio(false);cin.tie(0);
using namespace std;

ifstream fin("sdo.in");
ofstream fout("sdo.out");
int v[3000001];
int n,k;
int pivot(int l, int st, int dr)
{
    int p=0;
    for (int i=st;i<=dr;i++)
        if (v[i]<=v[l])
            p++;
    swap(v[l],v[p]);
    while (st<dr)
    {
        while (st<dr and v[st]<v[l])
            st++;
        while (st<dr and v[dr]>v[l])
            dr--;
        if (st<dr)
        swap(v[st],v[dr]);
    }
    return p;
}
void qsort(int st, int dr, int k)
{
    if (st==dr)
    {
        fout<<v[st];
        return;
    }
    int p=pivot((st+dr)/2,st,dr);
    if (p-st+1>=k)
        qsort(st,p,k);
    else
        qsort(p+1,dr,k-(p-st+1));
}
int main()
{
    fast
    fin>>n>>k;
    for (int i=1;i<=n;i++)
        fin>>v[i];
    qsort(1,n,k);
    return 0;
}