Cod sursa(job #1961423)

Utilizator andreigasparoviciAndrei Gasparovici andreigasparovici Data 11 aprilie 2017 09:19:08
Problema Statistici de ordine Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.93 kb
#include <bits/stdc++.h>

using namespace std;

const int SIZE = 100000;
class InParser
{
private:
    char buffer[SIZE];
    int index;
    inline char next_char()
    {
        if(index == SIZE)
        {
            index = 0;
            fread(buffer, 1, SIZE, stdin);
        }
        return buffer[index++];
    }
public:
    InParser()
    {
        index = 0;
        fread(buffer, 1, SIZE, stdin);
    }
    InParser& operator>>(int &x)
    {
        x = 0;
        char c = next_char();
        while(!isdigit(c))
            c = next_char();
        while(isdigit(c))
        {
            x = x * 10 + c - '0';
            c = next_char();
        }
        return *this;
    }
};

int a[3000001], n, k;

int main()
{
    freopen("sdo.in", "r", stdin);
    freopen("sdo.out", "w", stdout);

    InParser in;

    in>>n>>k;
    for(int i = 0; i < n; i++)
        in>>a[i];

    nth_element(a,a+k,a+n+1);
    printf("%d ",a[k]);

    return 0;
}