Cod sursa(job #2341440)

Utilizator MateiAruxandeiMateiStefan MateiAruxandei Data 11 februarie 2019 20:22:55
Problema Statistici de ordine Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.87 kb
#include <cstdio>
#include <algorithm>
#include <vector>
#include <iostream>

using namespace std;

vector <int> v;
const int buffsize = 655536;
char buffer[buffsize + 1];
int poz = buffsize;

char getCh(){
    if(poz == buffsize){
        fread(buffer, 1, buffsize, stdin);
        poz = 0;
    }
    return buffer[poz++];
}

int readInt(){
    int num = 0;
    char ch = getCh();
    while(1){
        if(ch == ' ' || ch == '\n')
            break;
        num = num * 10 + (ch - '0');
        ch = getCh();
    }
    return num;
}

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

    int n, k;
    n = readInt();
    k = readInt();

    for(int i = 1; i <= n; ++i)
        v.push_back(readInt());

    nth_element(v.begin(), v.begin() + k - 1, v.end());
    printf("%d\n", v[k - 1]);
    return 0;
}