Pagini recente » Cod sursa (job #352686) | Cod sursa (job #182909) | Cod sursa (job #823014) | Cod sursa (job #3237360) | Cod sursa (job #1011675)
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
ifstream f("sdo.in");
ofstream g("sdo.out");
int a[3000000];
void sort(int st, int dr) {
int i = st, j = dr;
int t;
int pivot = a[(st + dr) / 2];
while (i <= j) {
while (a[i] < pivot)
i++;
while (a[j] > pivot)
j--;
if (i <= j) {
t = a[i];
a[i] = a[j];
a[j] = t;
i++;
j--;
}
};
if (st < j)
sort(st, j);
if (i < dr)
sort(i, dr);
}
int main()
{
int n,m; f>>n>>m;
for(int i=0;i<n;i++)
{
f>>a[i];
}
sort(0,n-1);
for(int i=0;i<n;i++)
{
cout<<a[i]<<" ";
}
g<<a[m-1];
return 0;
}