Cod sursa(job #2718454)

Utilizator IoanaDraganescuIoana Draganescu IoanaDraganescu Data 8 martie 2021 19:15:53
Problema Statistici de ordine Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.44 kb
#include <iostream>
#include <fstream>
#include <algorithm>

using namespace std;

ifstream fin("sdo.in");
ofstream fout("sdo.out");

const int NMax = 3 * 1e6;

int n, k;
int v[NMax + 5];

void Read(){
    fin >> n >> k;
    for (int i = 1; i <= n; i++)
        fin >> v[i];
}

void Print(){
    nth_element(v + 1, v + k, v + n + 1);
    fout << v[k] << '\n';
}

int main(){
    Read();
    Print();
    return 0;
}