Pagini recente » Cod sursa (job #3224197) | Cod sursa (job #975465) | Cod sursa (job #913634) | Cod sursa (job #2988068) | Cod sursa (job #374241)
Cod sursa(job #374241)
# include <stdio.h>
int a[3000005],i,n,aux,k,x;
void poz (int i,int j)
{
int ok=0;
while (i!=j)
{
if (a[i]>a[j])
{
if (ok==0)
ok=1;
else
ok=0;
aux=a[i];
a[i]=a[j];
a[j]=aux;
}
if (ok==0)
j--;
else
i++;
}
x=i;
}
int rez (int i,int j)
{
if (x==k)
return a[x];
else
{
poz (i,j);
if (x<k)
{
return rez (x+1,j);
}
else
{
return rez (i,x-1);
}
}
}
int main ()
{
freopen ("sdo.in","r",stdin);
freopen ("sdo.out","w",stdout);
scanf ("%i%i",&n,&k);
for (i=1;i<=n;i++)
scanf ("%i",&a[i]);
printf ("%i",rez (1,n));
return 0;
}