Cod sursa(job #1842660)
| Utilizator | Data | 7 ianuarie 2017 13:38:36 | |
|---|---|---|---|
| Problema | Statistici de ordine | Scor | 20 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.56 kb |
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
ifstream f("sdo.in");
ofstream g("sdo.out");
int n,k,i,x[3000010];
void go(int,int);
int main()
{
f>>n>>k;
for(i=1;i<=n;i++)
f>>x[i];
go(1,n);
g<<x[k];
return 0;
}
void go(int lo,int hi)
{
int st=lo,dr=hi,mi;
if(lo==hi)return;
mi=x[(lo+hi)/2];
do
{
while(x[st]<mi)st++;
while(x[dr]>mi)dr--;
if(st<dr){swap(x[st],x[dr]);st++;dr--;}
}
while(st<=dr);
if(k<=dr)go(lo,dr);
else go(st,hi);
}
