Editorial
Fix a width and a target height . It is sufficient to use the largest elements of for the chosen interval. Sort the interval's values increasingly and those values decreasingly. The interval is feasible exactly when every paired sum is at least .
For every , let be the number of elements satisfying . If the values in a window are sorted as , feasibility is equivalent to for every .
Maintain the frequency of in a sliding window. Define . All must be non-positive. A segment tree storing the maximum prefix sum of supports insertion, deletion, and checking in .
For every width , binary-search the largest feasible and maximize . The time complexity is .