Cod sursa(job #739119)

Utilizator test0Victor test0 Data 22 aprilie 2012 10:47:35
Problema Statistici de ordine Scor 20
Compilator cpp Status done
Runda Arhiva educationala Marime 0.61 kb
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
vector<int>h;

int n,k;

bool cmp(int a,int b){ return a>b; }

int main(){
    int x,i;
    freopen("sdo.in","r",stdin);
    freopen("sdo.out","w",stdout);
        scanf("%d %d",&n,&k);
        for(int i=1;i<=n;i++){
            scanf("%d",&x);
            h.push_back(x);
            push_heap(h.begin(),h.end(),cmp); }
        i=1;
        while(i<k){
            x=h[0];
            while(h.size()>0&&h[0]==x){
                pop_heap(h.begin(),h.end(),cmp);
                h.pop_back(); }
            i++; }
        printf("%d\n",h[0]);
}