Mai intai trebuie sa te autentifici.
Cod sursa(job #1023428)
Utilizator | Data | 6 noiembrie 2013 22:15:09 | |
---|---|---|---|
Problema | Statistici de ordine | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.75 kb |
#include<fstream>
using namespace std;
ifstream f("sdo.in");
ofstream g("sdo.out");
long v[500001], n;
int qSort(long vector[],long st,long dr, long k)
{
long temp,min,max,mijl;
mijl = vector[st+(dr-st)/2];
min = st; max = dr;
do
{
while(vector[min] < mijl) min++;
while(vector[max] > mijl) max--;
if(min <= max)
{
temp = vector[min];
vector[min++] = vector[max];
vector[max--] = temp;
min++;
max--;
}
}while(min <= max);
if(k <= max) qSort(vector,st,max,k);
if(min <= k) qSort(vector,min,dr, k);
return v[k];
}
int main()
{
long i, k;
f>>n>>k;
for(i=1;i<=n;i++)
f>>v[i];
qSort(v,1,n, k);
g<<v[k];
f.close();
g.close();
return 0;
}