시간 제한메모리 제한제출정답맞힌 사람정답 비율
3 초 (추가 시간 없음) 1024 MB156640.000%

문제

An athlete is participating in a new sport that is the perfect mix of hopscotch and triple jumping. For this jury sport, $n$ squares are laid out on the ground in a line, with equal distances between them. The first phase is the approach, where an athlete sprints towards the first square, in which they start their first jump. Then, they may jump on any number of other squares, and must finally land in the last square.

The jury has given a predetermined number of points to jumping in each square, and the score of the athlete will be the sum of the scores of all the squares they jump in, including the very first and last squares.

Due to the nature of this sport, once the athlete starts jumping, they can not accelerate anymore, and the length of consecutive jumps can never increase. Naturally, it is also impossible to reverse direction.

Given the points the jury has allocated to each square, find the maximal possible score an athlete can get on this event.

입력

The input consists of:

  • One line with an integer $n$ ($2\leq n\leq 3000$), the number of squares.
  • One line with $n$ integers $p_1, p_2, \dots, p_n$ ($-10^9\leq p_i\leq 10^9$), the number of points the jury awards for jumping on each of the squares.

출력

Output the maximum score that an athlete can get.

예제 입력 1

4
1 -1 1 1

예제 출력 1

3

예제 입력 2

4
1 1 -1 1

예제 출력 2

2

예제 입력 3

3
-1 1 -1

예제 출력 3

-1

예제 입력 4

3
-1 -1 -1

예제 출력 4

-2

출처

ICPC > Regionals > Europe > Northwestern European Regional Contest > Benelux Algorithm Programming Contest > BAPC 2021 D번

  • 문제를 만든 사람: Onno Berrevoets