RANK - ICO ONLINE JUDGE

I am trying to solve the problem http://www.iarcs.org.in/inoi/contests/jan2005/Advanced-2.php . My code:
http://ideone.com/BiRleN

Can anyone point out where am i getting wrong?

1 Like

The best solution is to store the elements in an ordered map and find the rank of an element using binary search.

1 Like

As Your code is not able to pass the test cases…definitely it is wrong algorithm wise*

just do sum manually run you code with pan paper and analyze the code how control flow and what all action are taking place …then definitely you will got to know why u got wrong answer…

very simple and bruteforce approch is here later I will provide you optimize version…

just take a simple array of size : N



repeat N times
   scanf curr new coming element..
   just insert new coming element into array at last position
   sort array using merge sort i.e.syntax sort(A,A+i); i=number of element in A at present
   then use binary search for getting index of curr
   print index+1;


  • Time Complexity : O(N*(1+1+NxlogN+logN+1)) :: NxNxlogN
  • Space Complexity : O(N)


Have you tried enough…Do you want see code…click on this link

Now I trying this problem using map…I will update soon that code too…
Happy coding