ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Common Board

1025... -_-b why.... wa
Posted by ^oo^ 11 May 2002 11:21
/*
   1025 Democracy in danger.
*/
#include <stdio.h>
int i,n,tot,v[101];

int partation(int arr[], int low, int high)
{
  int pivotkey=arr[low];
  while (low<high)
  {
    while ((low<high) && (arr[high]>=pivotkey)) high--;
    arr[low]=arr[high];
    while ((low<high) && (arr[low]<=pivotkey)) low++;
    arr[high--]=arr[low];
  }
  arr[low]=pivotkey;
  return low;
}

int select(int arr[], int low, int high, int Nth)
{
  int pivotloc;
  pivotloc=partation(arr, low, high)+1;
  if (low==high) return arr[low];
  if (Nth<=pivotloc)
    return select(arr, low, pivotloc-1, Nth);
  else
    return select(arr, pivotloc, high, Nth-pivotloc);
}

int main()
{
  scanf("%d",&n);
  for (i=0; i<n; i++)
    scanf("%d",&v[i]);
  for (i=1; i<=n/2+1; i++)
    tot+=(select(v, 0, n-1, i)+1)/2;
  printf("%d\n",tot);
  return 0;
}