Pagini recente » Cod sursa (job #337714) | Cod sursa (job #201043) | Cod sursa (job #2010320) | Cod sursa (job #750821) | Cod sursa (job #2426968)
//ALEX ENACHE
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <time.h>
#include <iomanip>
#include <deque>
#include <math.h>
#include <cmath>
#include <assert.h>
#include <stack>
#include <bitset>
#include <random>
#include <chrono>
using namespace std;
const double PI = acos(-1);
const double eps = 1e-6;
inline long long lgput(long long a , long long b , long long mod) {
long long ret = 1;
while( b ){
if(b & 1) ret = (ret * a) % mod;
a = (a * a) % mod;
b >>= 1;
}
return (ret%mod);
}
inline long long inv(long long x , long long MOD) {
return lgput(x, MOD - 2, MOD);
}
inline bool exist (double nr){
return (nr < -eps) || (nr > eps);
}
long long big_rand(){
return rand () * RAND_MAX + rand();
}
//-----------------------------------------------------------------
//#include <iostream>
#include <fstream>
ifstream cin ("sdo.in");ofstream cout ("sdo.out");
int v[3000100];
int st[3000100];
int dr[3000100];
int main() {
//freopen("input", "r", stdin);freopen("output", "w", stdout);
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cout << setprecision(10) << fixed;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
srand(time(nullptr));
int n , m;
cin>>n>>m;
for (int i=1; i<=n; i++){
cin>>v[i];
}
while (true){
int ok = 0;
for (int i=2; i<=n; i++){
if (v[i] != v[i-1]){
ok = 1;
}
}
if (!ok){
break;
}
int pos = (big_rand() % n) + 1;
int ST = 0;
int DR = 0;
for (int i=1; i<=n; i++){
if (v[i] <= v[pos]){
ST++;
st[ST] = v[i];
}
else{
DR++;
dr[DR] = v[i];
}
}
if (ST >= m){
for (int i=1; i<=ST; i++){
v[i] = st[i];
}
n = ST;
}
else{
m -= ST;
for (int i=1; i<=DR; i++){
v[i] = dr[i];
}
n = DR;
}
}
cout<<v[1];
return 0;
}