Pagini recente » Cod sursa (job #2220125) | Cod sursa (job #2587851) | Cod sursa (job #1296557) | Cod sursa (job #148549) | Cod sursa (job #532543)
Cod sursa(job #532543)
#include <iostream>
#include <fstream>
#include <vector>
#include <utility>
#define MOD 2999999
using namespace std;
typedef pair <int, long long> pr;
typedef pr * ppr;
int N, K;
int index, sum, position, counter, remainder, modulo;
int L[340];
long long rv, answer;
vector <ppr> H[MOD + 4];
vector <ppr> :: iterator it;
int main()
{
ifstream f("sdo.in");
f >> N >> K;
for(index = 0; index < N; ++index)
{
f >> rv;
ppr key = new pr();
key->first = rv / MOD + 1;
key->second = rv;
modulo = rv % MOD;
if(H[modulo].size() == 0)
{
ppr max = new pr();
max->first = 0;
max->second = 0;
H[modulo].push_back(max);
}
if(key->first > H[modulo][0]->second)
H[modulo][0]->second = key->first;
H[modulo].push_back(key);
++L[key->first];
}
f.close();
index = 0;
while(sum < K)
sum += L[++index];
position = index;
sum -= L[position];
remainder = K - sum;
for(index = 0, counter = 1; index < MOD && counter <= remainder; ++index)
{
if(H[index].size() == 0)
continue;
if(H[index].at(0)->second >= position)
{
for(it = H[index].begin(); it != H[index].end(); ++it)
if((*it)->first == position)
{
if(counter != remainder)
++counter;
else
{
answer = (*it)->second;
++counter;
break;
}
}
}
}
ofstream g("sdo.out");
g << answer;
g.close();
return 0;
}