Pagini recente » Cod sursa (job #262896) | Cod sursa (job #88438) | Cod sursa (job #744886) | Cod sursa (job #1096534) | Cod sursa (job #2037677)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("sdo.in");
ofstream fout("sdo.out");
unsigned long v[4100000], n, k;
void citire(unsigned long& n, unsigned long& k)
{
unsigned long i;
fin>>n>>k;
for(i=1;i<=n;i++)
{
fin>>v[i];
}
}
void quicksort(unsigned long x1, unsigned long x2,unsigned long& V_K)
{
unsigned long i, j, aux, pivot;
i=x1;
j=x2;
aux=(x1+x2)/2;
pivot=v[aux];
while(i<=j)
{
while(v[i]<pivot)
{
i=i+1;
}
while(v[j]>pivot)
{
j=j-1;
}
if(i<=j)
{
aux=v[i];
v[i]=v[j];
v[j]=aux;
i=i+1;
j=j-1;
}
}
if(k==j+1)
{
V_K=v[k];
}
else
{
if(k<j+1)
{
quicksort(x1, j, V_K);
}
else
{
quicksort(i, x2, V_K);
}
}
}
void afisare(unsigned long V_K)
{
fout<<V_K;
}
int main()
{
unsigned long V_K;
citire(n, k);
quicksort(1, n, V_K);
afisare(V_K);
}