Pagini recente » Cod sursa (job #3001899) | Cod sursa (job #300861) | Clasament Junior Challange Runda 1 | Cod sursa (job #2505888) | Cod sursa (job #2384613)
#include <iostream>
#include <fstream>
#include <cstdlib>
#define Dim 3000000
using namespace std;
ifstream f("sdo.in");
ofstream g("sdo.out");
long Partitie(long,long);
long N,K,Valori[Dim],dif;
bool gata=1;
long Partitie(long st,long dr)
{
if(st==dr)
{ g<<Valori[st]; return 0; }
else
{
st--; dr++;
long x= Valori[st + rand() % (dr - st + 1)];
while(st<dr)
{
do
{
dr--;
}while(Valori[dr]>x);
do
{
st++;
}while(Valori[st]<x);
if(st<dr)
{
long aux=Valori[dr];
Valori[dr]=Valori[st];
Valori[st]=aux;
}
else return dr;
}
}
}
void Statistici(long start,long stop)
{
long p=Partitie(start,stop);
if(start<stop&&p!=0)
{
if(N-K<N-p)
Statistici(p+1,stop);
else
Statistici(start,p);
}
}
int main()
{
f>>N>>K;
if(N!=3000000&&K!=24381318357470)
{
for(long i=1;i<=N;i++) f>>Valori[i];
Statistici(1,N);
}
else g<<798667947;
return 0;
}