Editorial for MALD Contest 1 P4 - Scratch Cat and Demolition
Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.
Submitting an official solution before solving the problem yourself is a bannable offence.
Linear Solution
Create a histogram where the height at is . If there is no forbidden floor at , the histogram height at will be set to "infinity". Now the problem is reduced to finding the maximum rectangle area in the histogram, but the area cannot be greater than or equal to "infinity". Set an "infinity" value larger than the largest area possible value, . (every building except for one is infinity) will not overflow a -bit integer.
Note that there are many other solutions to this problem and solutions also pass.
Intended Complexity:
Comments