아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Archeologists

시간 제한3초메모리 제한1024 MB

요약
일직선 위의 각 지점에서 깊이를 정하되 인접한 깊이 차가 1 이하이고 양 끝은 1 이하가 되도록 하여 총이익을 최대로 만든다.
난이도

보통10점 중 7점

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

문제

Your treasure hunter team has just discovered a giant archeological site, full of precious metals and valuable antiquities. The site is composed of nn digging spots on a line.

The initial plans suggest that each of the nn digging spots has a net profit associated with it. The ii-th spot’s associated profit is p_ip\_i. More specifically, this means that your team would gain p_ip\_i dollars for each meter dug in the ii-th spot. Note that p_ip\_i may also be negative, which means that the running cost of the excavating machinery surpasses the actual gain from digging in the ii-th spot.

Naturally, you would want to dig as much as possible in the most profitable spots. However, in order not to cause landslides, you are not allowed to have slopes that are too steep. More precisely, for any two adjacent spots, the difference between the digging depth at these spots cannot differ by more than 11 meter. In particular, spots 11 and nn can be dug only at most 11 meter deep.

What is the largest net profit that you can obtain, under these conditions?

For instance, a valid digging plan that turns out to be optimal in the case of the first example input is illustrated below. The net profit of such plan is 88.

입력

The first line of the input will contain a positive integer nn (1≤n≤250,0001 \le n \le 250\\,000).

The second line of the input will contain nn integers p_ip\_i (−106≤p_i≤106-10^6 \le p\_i \le 10^6), separated by spaces.

출력

Output exactly one integer, the largest profit that you can obtain.

예제3

  1. 예제 1

    입력
    5
    1 3 -4 2 1
    
    예상 출력
    8
    
  2. 예제 2

    입력
    4
    1 1 -2 3
    
    예상 출력
    5
    
  3. 예제 3

    입력
    5
    -1 -3 0 -5 -4
    
    예상 출력
    0