Pagini recente » Cod sursa (job #1225288) | Cod sursa (job #338642) | Cod sursa (job #987671) | Cod sursa (job #1846998) | Cod sursa (job #2026111)
#include <iostream>
#include <fstream>
#include <algorithm>
#define ARRAY_SIZE 3000001
#define BUFF_SIZE 100001
using namespace std;
ifstream in("sdo.in");
ofstream out("sdo.out");
char buffer[BUFF_SIZE];
int pos = 0;
void Read(int &a) {
while (!isdigit(buffer[pos]))
if (++pos == BUFF_SIZE)
in.read(buffer, BUFF_SIZE), pos = 0;
a = 0;
while (isdigit(buffer[pos])) {
a = a * 10 + buffer[pos] - '0';
if (++pos == BUFF_SIZE)
in.read(buffer, BUFF_SIZE), pos = 0;
}
}
int _array[ARRAY_SIZE];
int main() {
int n, k;
Read(n), Read(k);
for (int i = 1; i <= n; i++)
Read(_array[i]);
in.close();
nth_element(_array, _array + k, _array + n + 1);
out << _array[k] << "\n";
out.close();
return 0;
}