Editorial for COCI '16 Contest 5 #3 Unija
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.
It is enough to observe only the right half of the image and in the end double the result. The solution is to sum the heights of -columns for , which can be done using a for loop.
How to determine the height of the column at coordinate ? It is larger than or equal to the height of column at coordinate . It is larger if a rectangle exists that ends at coordinate and is higher than the column at coordinate , otherwise it is equal. Therefore, initially, we need to store the -coordinates where the given rectangles end and their heights, then traverse the -columns "backwards", towards the beginning, in order to apply the aforementioned formula.
Comments