Pagini recente » Cod sursa (job #2904039) | Cod sursa (job #1189544) | Cod sursa (job #844848) | Cod sursa (job #2550549) | Cod sursa (job #475076)
Cod sursa(job #475076)
#include<iostream>
#include<fstream>
#include<time.h>
#include<unistd.h>
#define N 100000
using namespace std;
int a[3000010], k, n;
int partition(int lo, int hi){
int aux = a[hi];
a[hi] = a[k];
a[k] = aux;
int pos = lo, i;
for ( i = lo; i <= hi-1; i++ )
if (a[i] <= a[hi]){
aux = a[i];
a[i] = a[pos];
a[pos] = aux;
pos++;
}
aux = a[pos];
a[pos] = a[hi];
a[hi] = aux;
return pos;
}
int quick(int lo, int hi){
int x, nx, i;
x = partition(lo, hi);
if (x == k)
return a[k];
else
if (x < k)
return quick(x+1, hi);
else
return quick(lo, x-1);
}
int main(){
ifstream f("sdo.in");
ofstream g("sdo.out");
int i;
f>>n>>k;
k = k-1;
for (i = 0; i < n; i++)
f>>a[i];
int x = 5777;
x = quick(0, n-1);
g<<x<<'\n';
return 0;
}