Pagini recente » Cod sursa (job #2714841) | Cod sursa (job #1764699) | Cod sursa (job #3124155) | Cod sursa (job #1758653) | Cod sursa (job #1033490)
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <string>
#include <stdlib.h>
#include <assert.h>
#include <time.h>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <queue>
#include<cstdlib>
using namespace std;
#define MAXN 3000001
#define radical3 1.7320508075
#define MAXDIFF 2000000000
#define PI 3.141592653
double eps = 1e-3;
int i,n,k,v[3000001];
void statistici_ordin(int st,int dr)
{
int min,max,mij;
mij=v[(st+dr)/2];
min=st;
max=dr;
while (min < max)
{
while (v[min] < mij)
min++;
while (v[max] > mij)
max--;
if (min <= max)
{
int aux = v[min];
v[min] = v[max];
v[max] = aux;
min++;
max--;
}
}
if (k <= max && st < max)
statistici_ordin (st, max);
if (k >= min && min < dr)
statistici_ordin (min, dr);
}
int main()
{
FILE *f = fopen("sdo.in", "r");
FILE *g = fopen("sdo.out", "w");
fscanf(f, "%d %d", &n, &k);
for (int i = 1; i <= n; i++)
{
fscanf(f, "%d", &v[i]);
}
statistici_ordin(1, n);
fprintf(g, "%d", v[k]);
fclose(f); fclose(g);
return 0;
}