Cod sursa(job #1033559)
Utilizator | Data | 17 noiembrie 2013 10:46:00 | |
---|---|---|---|
Problema | Statistici de ordine | Scor | 60 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.81 kb |
#include <fstream>
using namespace std;
ifstream in("sdo.in");
ofstream out("sdo.out");
int a[3000000],n;
void quicksort(int st, int dr)
{
int i = st, j = dr;
int aux;
int p = a[(st+dr) / 2];
while(i <= j)
{
while(a[i] < p)
i++;
while(a[j] > p)
j--;
if(i <= j)
{
aux = a[i];
a[i] = a[j];
a[j] = aux;
i++;
j--;
}
}
if(st < j)
quicksort(st, j);
if(i < dr)
quicksort(i, dr);
}
int main()
{
int i,k;
in >> n >> k;
for(i = 1 ; i <= n ; i++)
in >> a[i];
quicksort(1,n);
out << a[k];
return 0;
}