ZCO Rectangle

Hello, I tried to solve - https://www.codechef.com/ZCOPRAC/problems/ZCO15004

My code is http://pastebin.com/bEFStFD7

Unfortunately my algorithm isn’t efficient enough, it times out in the second subtasks

First the points are sorted by the values of their x axis and then area is calculated between two adjacent points with y = 500. This is easy because the rectangles are guaranteed to be on the x axis.

After this points are sorted by values of their y axis. Then I keep track of all points for x axis. Find adjacent x axis points using binary search and then find the area. The code should be able to explain better what I’m trying to say.

However it seems to be too slow. Can anyone point out a way to make it faster?

Fixed it. Working code - http://pastebin.com/ed9dFF7y

With this I’ve finished all problems in the practice contest. If anyone needs the code for any of the questions feel free to contact me.