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

Discussion of Problem 1510. Order

WA6
Posted by Jumabek_Alihonov 14 Oct 2011 16:42
this is my solutioon please help me!


#include <iostream>
#include <stdio.h>
using namespace std;
long a[50001], sum=0;
void merge(long,long,long);
void merge_sort(long low,long high)
{
 long mid;
 if(low<high)
 {
  mid=(low+high)/2;
  merge_sort(low,mid);
  merge_sort(mid+1,high);
  merge(low,mid,high);
 }
}
void merge(long low,long mid,long high)
{
 long h,i,j,b[50001],k;
 h=low;
 i=low;
 j=mid+1;
 while((h<=mid)&&(j<=high))
 {
  if(a[h]<=a[j])
  {
   b[i]=a[h];
   h++;
  }
  else
  {
   b[i]=a[j]; sum+=mid-h+1;
   j++;
  }
  i++;
 }
 if(h>mid)
 {
  for(k=j;k<=high;k++)
  {
   b[i]=a[k];
   i++;
  }
 }
 else
 {
  for(k=h;k<=mid;k++)
  {
   b[i]=a[k];
   i++;
  }
 }
 for(k=low;k<=high;k++) a[k]=b[k];
}

int main(){

 long num,i,a[50001];;
 cin>>num;
 for(i=1;i<=num;i++)
 {
  cin>>a[i] ;
 }if(num==1)cout<<a[1];
 else{
 merge_sort(1,num);
 cout<<a[num/2];
}return 0;}