For maximization: negate all values, find minimum, negate result. Or use upper envelope instead of lower. Upper envelope: the piecewise function giving maximum y at each x. Maintain with the same deque logic, but flip comparisons. Alternatively: insert lines into a lower envelope CHT, then negate the query result. Watch for integer overflow with large prefix sums. Use long long or 128-bit integers if needed.
Time complexity: .
Space complexity: with monotonic CHT.