Mai intai trebuie sa te autentifici.
Cod sursa(job #3244110)
Utilizator | Data | 23 septembrie 2024 17:05:55 | |
---|---|---|---|
Problema | Statistici de ordine | Scor | 50 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.58 kb |
#include <fstream>
using namespace std;
int h[500003];
int n, k;
void quicksort(int st, int dr){
int mij=(st+dr)/2;
int i=st, j=dr, mijloc=h[mij];
while(i<=j){
while(h[i]<mijloc)
i++;
while(h[j]>mijloc)
j--;
if(i<=j){
swap(h[i], h[j]);
i++, j--;
}
}
if(j>st&&k<=j)
quicksort(st, j);
if(i<dr&&k>=i)
quicksort(i, dr);
}
int main(){
ifstream fin("sdo.in");
ofstream fout("sdo.out");
fin>>n>>k;
for(int i=1;i<=n;i++)
fin>>h[i];
quicksort(1, n);
fout<<h[k];
return 0;
}