Use maximal histogram, O(n^2)