Logo
(追記) (追記ここまで)

21905번 - Archeologists 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
3 초 1024 MB104604671.875%

문제

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

The initial plans suggest that each of the $n$ digging spots has a net profit associated with it. The $i$-th spot’s associated profit is $p_i$. More specifically, this means that your team would gain $p_i$ dollars for each meter dug in the $i$-th spot. Note that $p_i$ may also be negative, which means that the running cost of the excavating machinery surpasses the actual gain from digging in the $i$-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 1ドル$ meter. In particular, spots 1ドル$ and $n$ can be dug only at most 1ドル$ 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 8ドル$.

입력

The first line of the input will contain a positive integer $n$ (1ドル \le n \le 250,000円$).

The second line of the input will contain $n$ integers $p_i$ ($-10^6 \le p_i \le 10^6$), separated by spaces.

출력

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

제한

예제 입력 1

5
1 3 -4 2 1

예제 출력 1

8

예제 입력 2

4
1 1 -2 3

예제 출력 2

5

예제 입력 3

5
-1 -3 0 -5 -4

예제 출력 3

0

힌트

출처

ICPC > Regionals > Europe > Southeastern European Regional Contest > SEERC 2020 A번

Contest > Open Cup > 2020/2021 Season > Stage 17: Grand Prix of Southern Europe A번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /