Pagini recente » Cod sursa (job #1021633) | Cod sursa (job #1556689) | Istoria paginii utilizator/harsan_sabin | Cod sursa (job #2817029) | Cod sursa (job #2026068)
#include <iostream>
#include <fstream>
#define ARRAY_SIZE 3000001
using namespace std;
ifstream in("sdo.in");
ofstream out("sdo.out");
int _array[ARRAY_SIZE];
void quicksort(int x, int y, int k) {
if (x < y) {
int i = x, j = y, pivot = _array[x + (y - x) / 2];
while (i <= j) {
while (_array[i] < pivot)
i++;
while (_array[j] > pivot)
j--;
if (i <= j) {
swap(_array[i], _array[j]);
i++;
j--;
}
}
if (i <= k && k <= y)
quicksort(i, y, k);
if (j >= k && k >= x)
quicksort(x, j, k);
}
}
int main()
{
int n, k;
in >> n >> k;
for (int i = 1; i <= n; i++)
in >> _array[i];
in.close();
quicksort(1, n, k);
out << _array[k] << "\n";
out.close();
return 0;
}