How to solve SPOJ GOODG?

I was solving questions related to convex hull trick then I got stuck at this one SPOJ.com - Problem GOODG but the lines will not be sorted, of course. So, I tried to to implement a Li Chao tree
2GfBzk - Online C++0x Compiler & Debugging Tool - Ideone.com but it does not does not work. Any help will be appreciated.