I was solving problems from the codeforces.ru but I couldn't solve a problem and the editorial said to use convex hull trick.
I tried to read this article about convex hull trick but couldn't understand it.
Can anyone tell me exactly what is convex hull trick?
thanks in advance.
If you have a set of lines Yi = Ai * X + Bi, then the problem is finding the smallest Yi for given X. Naively, you could try to evaluate all Yi for this X and choose the smallest one. But if you want to evaluate a series of values for X, then you can better determine where the Yi intersect and then for each interval between the intersections determine which Yi is the smallest. Then, given an X, you choose the corresponding interval and only evaluate the Yi that is smallest on that interval.
(Visualized by the green lines here: http://wcipeg.com/wiki/File:Convex_hull_trick1.png)