### mentalist's blog

By mentalist, 6 years ago,

I recently read the article from PEG Wiki about the convex hull trick, which can be applied to speed up dynamic programming algorithms (Link to the website) . This optimisation can only apply when certain conditions are met. Surprisingly, at the end of the article I read that we can achieve a fully dynamic variant of the trick (meaning that there are no conditions of applicability) if we store the lines in a std::set. Although I have understood the approach mentioned, I always fail when I try to implement it. Could someone point me to an implementation of the dynamic convex hull trick, and some problems where I can practice it? Thanks in advance.

• +3

 » 6 years ago, # |   +1
•  » » 6 years ago, # ^ | ← Rev. 2 →   +11 Thank you very much! This is exactly what i was looking for. By the way, I found a really nice problem for everyone who is interested in practicing this technique: http://www.spoj.com/problems/GOODG/
•  » » » 6 years ago, # ^ |   +1 I am the author of the dynamic convex hull code dj3500 linked to, so please write me if you find any problems :)
•  » » » » 6 years ago, # ^ |   0 Thank you very much :)
•  » » » 5 years ago, # ^ |   0 Just as a warning for future readers.You don't need the fully dynamic variant to solve this problem. You can solve it easily with a different approach. :)
 » 6 years ago, # |   +1 Here are many good convex-hull trick problems (also in the comments): http://codeforces.com/blog/entry/8219
 » 5 years ago, # | ← Rev. 2 →   +3 Here is my alternative implementation. Hope this will help somebody. Note: this class can be used to find both max and min values.
•  » » 5 years ago, # ^ |   0 Thanks a lot!
•  » » 5 years ago, # ^ |   0 This helped me a lot, thanks for all the work you put in.
•  » » 4 years ago, # ^ |   -29 Hey , I wanted to ask questions about your implementation!Does your Code needs any specific condition that is decreasing slopes or increasing values of x?