fork download
  1. #include <stdio.h>
  2.  
  3. #define SIZE 250000
  4.  
  5. int a[SIZE], n;
  6.  
  7. long search_statistics(int l, int r, int k)
  8. {
  9. while (l < r)
  10. {
  11. int i = l, j = r;
  12. int x = a[(r - l) / 2 + l];
  13.  
  14. while (i <= j)
  15. {
  16. while (a[i] < x) i++;
  17.  
  18. while (a[j] > x) j--;
  19.  
  20. if (i <= j)
  21. {
  22. int t = a[i];
  23. a[i++] = a[j];
  24. a[j--] = t;
  25. }
  26. }
  27.  
  28. if (k <= j)
  29. r = j;
  30. else if (k >= i)
  31. l = i;
  32. else
  33. break;
  34. }
  35.  
  36. return a[k];
  37. }
  38.  
  39. int main()
  40. {
  41. int i;
  42. long double res;
  43.  
  44. scanf("%d", &n);
  45.  
  46. for (i = 0; i < n; i++)
  47. scanf("%d", &a[i]);
  48.  
  49. if (n % 2)
  50. res = search_statistics(0, n - 1, n / 2);
  51. else
  52. res = ((long double) search_statistics(0, n - 1, n / 2) / 2) + ((long double) search_statistics(0, n - 1, n / 2 - 1) / 2);
  53.  
  54. printf("%.1Lf", res);
  55.  
  56. return 0;
  57. }
Success #stdin #stdout 0s 3228KB
stdin
4
3
6
4
5
stdout
4.5