here is the problem
it's really an interesting problem but just a few people have solved it
I came up with o(n^2 * log2(2)) solution (using dp and segment tree)
it could pass only 40% of test cases
someone told me it could be solved using convex hull trick
so please explain your solution
thanks in advance
the problem