Cod sursa(job #1011675)

Utilizator PlatonPlaton Vlad Platon Data 17 octombrie 2013 09:41:09
Problema Statistici de ordine Scor 50
Compilator cpp Status done
Runda Arhiva educationala Marime 0.89 kb
#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;
}