#P8081. [COCI 2011/2012 #4] ZIMA
[COCI 2011/2012 #4] ZIMA
Description
You are given the temperatures over days. Define:
- If the temperature of a day is less than , then it is called a freezing day.
- If there are consecutive freezing days, then this is called a cold period of duration .
Several days before a cold period starts will be marked as being in an alert state. For a cold period with duration , the rules are:
- If this cold period is not the longest among all cold periods, then the days before it starts are marked as alert days.
- If this cold period is the longest among all cold periods, then the days before it starts are marked as alert days. In particular, if there are multiple longest cold periods, only one of them is marked for days, and the others are marked for days.
- If you are currently inside a cold period, you are not allowed to mark alert days for the current cold period, but if the conditions allow, you may mark alert days for future cold periods.
You may choose any one of the longest cold periods so that the rule is applied to it. Among all choices, find the maximum possible number of alert days.
Input Format
The first line contains a positive integer .
The second line contains integers , representing the temperatures over these days.
Output Format
Output the maximum number of days that are in the alert state.
8
1 -1 4 3 8 -2 3 -3
6
15
1 2 -1 2 3 4 5 6 1 4 8 3 -1 -2 1
8
Hint
[Sample 1 Explanation]
There are longest cold periods: .
When choosing as the cold period that needs days marked as alert before it starts, the number of alert days is maximized:
| Day | ||||||||
|---|---|---|---|---|---|---|---|---|
| Temperature | ||||||||
| In a cold period | No | Yes | No | Yes | No | Yes | ||
| In alert state | Yes | No | Yes | Yes | No | |||
[Constraints]
- For of the testdata, the longest cold period is unique.
- For of the testdata, , .
[Hints and Notes]
Translated from COCI 2011-2012 CONTEST #4 Task 2 ZIMA.
The score of this problem follows the original COCI setting, with a full score of . Since Luogu does not support non-integer scores, adjustments were made for cases where the score cannot be divided evenly.
Translated by ChatGPT 5
京公网安备 11011102002149号