Pagini recente » Sedinta 2007-11-07 | Rating Popovici Iulian (username) | Poliție | Cod sursa (job #2587740) | Cod sursa (job #373025)
Cod sursa(job #373025)
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
const char iname[] = "sdo.in";
const char oname[] = "sdo.out";
vector <int> V;
int main(void) {
ifstream in(iname);
int n, k;
assert(in >> n >> k);
assert(1 <= k && k <= n && n <= 3000000);
V.resize(n);
for (int i = 0; i < n; ++ i) {
assert(in >> V[i]);
assert(1 <= V[i] && V[i] <= 1000000000);
}
in.close();
nth_element(V.begin(), V.begin() + (k - 1), V.end());
ofstream(oname) << V[k - 1];
return 0;
}