Obstacle Course

시간 제한1초메모리 제한2048 MB

요약
홀수 도로의 높이는 주어지고 짝수 도로의 높이는 자유롭게 정할 수 있을 때, 연속한 높이 차가 1인 구간의 최대 길이를 최대로 만든다.
난이도

보통10점 중 7점

유형
그리디, 동적 계획법
정답자
아직 제출이 없습니다

문제

As a businessman and parkour enthusiast, Morgan owns an obstacle course consisting of NN road segments numbered from 11 to NN. These road segments are arranged sequentially such that road 11 is adjacent to road 22, road 22 is adjacent to road 33, ..., road N−1N - 1 is adjacent to road NN. Currently, each odd-numbered road segment has a height of a positive integer A_iA\_i, and each even-numbered road segment has a height of 00. In Morgan’s course, anyone can start from any road segment, parkour towards one direction, and stop at any road segment as long as they can reach that road segment.

As a beginner athlete, Adrian thinks that Morgan’s obstacle course may be too hard due to the height difference between any two consecutive roads. Adrian enjoys doing parkour whenever the height difference between two consecutive roads is exactly 11. If the next road segment has a difference of more than 11 from the current road segment, then Adrian cannot climb or jump down to the next road segment and will stop his parkour activity. On the other hand, if the next road segment has the same height as the current road segment, then Adrian will lose interest and stop his parkour activity. He will also stop his parkour activity if he reaches the end of the obstacle course, i.e. road segment NN or road segment 11.

As his friend, Morgan wants Adrian to be happy with the course. Adrian’s happiness is defined as the number of road segments that he parkoured before he lost interest and stops his parkour activity. Adrian will start from any road segment that will give him the largest happiness. Based on these facts, Morgan decided to change the heights of some (possibly none) even-numbered road segments such that Adrian’s largest happiness for the course is maximized. However, before he makes any changes, he asked you to determine the largest possible Adrian’s happiness that can be obtained after changing the height.

For example, let A_1..9=\[6,0,4,0,8,0,12,0,14]A\_{1..9} = \[6, 0, 4, 0, 8, 0, 12, 0, 14]. By changing AA into \[6,5,4,5,8,11,12,13,14]\[6, 5, 4, 5, 8, 11, 12, 13, 14], Adrian can do parkour from segment 11 to 44 or from segment 66 to 99, and his happiness will be 44, which is also the largest happiness after that change. There are some other changes that can make Adrian’s largest happiness equal to 44 as well, e.g. \[6,5,4,3,8,7,12,12,14]\[6, 5, 4, 3, 8, 7, 12, 12, 14], but no change can make Adrian’s largest happiness larger than 44.

Help Morgan to determine the largest possible Adrian’s happiness in his new course.

입력

Input begins with an integer NN (2≤N≤100,0002 ≤ N ≤ 100\\, 000) representing the number of road segments. The next line contains NN integers A_iA\_i (A_i=0A\_i = 0 if ii is even; 1≤A_i≤100,0001 ≤ A\_i ≤ 100\\, 000 if ii is odd) representing the height of segment ii from 11 to NN respectively.

출력

Output an integer in a single line that represents the largest possible Adrian’s happiness in Morgan’s new course.

예제4

  1. 예제 1

    입력
    9
    6 0 4 0 8 0 12 0 14
    
    예상 출력
    4
    
  2. 예제 2

    입력
    7
    3 0 5 0 5 0 7
    
    예상 출력
    7
    
  3. 예제 3

    입력
    6
    6 0 2 0 8 0
    
    예상 출력
    3
    
  4. 예제 4

    입력
    7
    4 0 6 0 10 0 9
    
    예상 출력
    4