Pagini recente » Cod sursa (job #963677) | Cod sursa (job #483937) | Cod sursa (job #1242017) | Cod sursa (job #1106812) | Cod sursa (job #1052254)
#include <fstream>
#define Nmax 3000100
using namespace std;
int N, K, V[Nmax];
void Part(int A, int B) {
int Left, Right, Pivot;
Left = A;
Right = B;
Pivot = V[(Left + Right) >> 1];
while(Left <= Right) {
while(V[Left] < Pivot)
++Left;
while(Pivot < V[Right])
--Right;
if(Left <= Right) {
swap(V[Left], V[Right]);
++Left; --Right;
}
}
if(K <= Right && A < Right)
Part(A, Right);
else
if(K >= Left && Left < B)
Part(Left, B);
}
void Read() {
ifstream in("sdo.in");
in >> N >> K;
for(int i = 1; i <= N; i++)
in >> V[i];
in.close();
}
void Write() {
ofstream out("sdo.out");
out << V[K] << '\n';
out.close();
}
int main() {
Read();
Part(1, N);
Write();
return 0;
}