Pagini recente » Cod sursa (job #2153428) | Cod sursa (job #2353591) | Cod sursa (job #2458682) | Cod sursa (job #37914) | Cod sursa (job #856860)
Cod sursa(job #856860)
#include<cstdlib>
#include<ctime>
#include<fstream>
using namespace std;
ifstream f("sdo.in");
ofstream g("sdo.out");
int n, k, a[3000001];
void sort(int l,int r)
{
if(l<r)
{
int rnd, val,x,y;
rnd=rand()%(r-l+1)+l;
x=l;
y=r;
val=a[rnd];
while(x<=y){
while( a[x] < val )
x++;
while( a[y] > val )
y--;
if( x <= y ){
int aux;
aux=a[x];
a[x]=a[y];
a[y]=aux;
x++;
y--;
}
}
if( ( x-y == 2 ) && ( k == x-1 ) )
g<<a[x-1]<<" ";
else
if(k>=x)
sort(x,r);
else sort(l,y);
}
else g<<a[l]<<" ";
}
int main(){
f>>n>>k;
srand ( time(NULL) );
int i;
for(i=1;i<=n;i++)
f>>a[i];
sort(1,n);
return 0;
}