The variable stores the length of the longest thaw.
The variable stores the length of the current thaw — that is, the number of consecutive days with a positive temperature.
For each day, the temperature value is analyzed:
if the temperature is positive, the value of is increased by ;
otherwise, is reset to .
During the processing of all days, the maximum among the values of is maintained and stored in the variable .
Example
Let us consider an example.
Algorithm implementation
Read the number of days .
scanf("%d", &n);The variable stores the length of the longest thaw.
The variable stores the length of the current thaw (the number of consecutive days with a positive temperature).
temp = res = 0;Process the temperatures for all days.
for (i = 0; i < n; i++)
{
scanf("%d", &cur);If cur > 0, increase the length of the current thaw by . Otherwise, reset its value to .
if (cur > 0) temp++; else temp = 0;Among all obtained values of the current thaw length, we maintain the maximum value.
if (temp > res) res = temp;
}Print the answer.
printf("%d\n", res);