Editorial for COCI '11 Contest 4 #2 Zima


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.

First, we traverse the given day temperatures and locate the winter periods. Every winter period starts with a negative number, and lasts until a positive number is encountered.

If there is a winter period starting with day A and lasting T days, we mark all days from A-2T to A-1 (inclusive) in some boolean array. This array tells us during which days are we allowed to announce the winter. We also keep track of the length of longest winter period so far.

Finally, we must choose one of the longest winter periods and allow it's announcing 3T days in advance. We do this by checking for each of the longest periods by how much will our solution increase if we choose that period, and then choosing the one that was optimal. This checking is easy to do by using the same array of booleans as before.


Comments

There are no comments at the moment.