Pagini recente » Cod sursa (job #2710090) | Cod sursa (job #1804099) | Cod sursa (job #1127183) | Cod sursa (job #698121) | Cod sursa (job #2610707)
#include <iostream>
#include <fstream>
#include <random>
#include <ctime>
using namespace std;
ifstream f("sdo.in");
ofstream g ("sdo.out");
int n, k, low[3000005], ech[3000005], high[3000005];
int quicksort_modificat(int dr, int k, int v[])
{
int pivot=rand()%dr;
int x=v[pivot];
int len_l=0,len_e=0, len_h=0;
for(int i=0; i<dr; i++)
{
if(v[i]<x)
{
low[len_l]=v[i];
len_l++;
}
else if(v[i]==x)
{
ech[len_e]=v[i];
len_e++;
}
else
{
high[len_h]=v[i];
len_h++;
}
}
if (k<=len_l)
quicksort_modificat(len_l, k, low);
else if (k<=len_l+len_e)
return ech[0];
else
{
k=k-(len_l+len_e);
quicksort_modificat(len_h, k, high);
}
}
int main()
{
f>>n;
f>>k;
for(int i=0; i<n; i++)
f>>high[i];
int val=quicksort_modificat(n, k, high);
g<<val;
return 0;
}