Pagini recente » Cod sursa (job #3192728) | Cod sursa (job #22779) | Cod sursa (job #534143) | Cod sursa (job #1174192) | Cod sursa (job #2274753)
#include <iostream>
#include <fstream>
#include <set>
using namespace std;
ifstream f("sdo.in") ;
ofstream g("sdo.out") ;
long long n , nr , x , a[90000] ;
void poz ( long long st, long long dr )
{
long long i = st , j = dr , pivot = a[(i+j)/2] ;
do{
while( (i < dr) && (a[i] < pivot) )
i ++ ;
while( (j > st) &&( a[j] > pivot) )
j -- ;
if( i <= j ){
swap( a[i] , a[j] ) ;
i ++ ;
j -- ;
}
if( j == nr ) {
g << a[j] ;
return ;
}
}while( i <= j ) ;
if( st < j )
poz( st , j ) ;
if( i < dr )
poz( i , dr ) ;
}
int main()
{ long long i ;
f >> n >> nr ;
for( i = 1 ; i <= n ; i ++ )
f >> a[i] ;
poz( 1 , n ) ;
//if( j != - 1 )
//g << a[nr] ;
}