Editorial for WC '18 Contest 2 S2 - Plutonium
Submitting an official solution before solving the problem yourself is a bannable offence.
Let's iterate over the days in reverse order, from down to , while filling in their actual values. We'll use to represent being allowed to take on any value based on , and we'll set for convenience.
When processing a day , we should first consider whether or not there's a conflict between it and day , such that there's no way to assign both of them valid values. This is only the case when , , and . If we encounter any instances of this, we should immediately output -1
.
We should then fill in day 's value. If is positive, then we must have . Otherwise, if , then we must have , and in the remaining case (when ), we can set .
Having filled in the values, we can examine them to determine the minimum and maximum possible number of withdrawals. Let's consider each day such that . If , then there must have been a withdrawal on that day. And if , it's possible that there either was or wasn't a withdrawal on that day.
Comments