AlgoLensArena
ContestlərProblemlərOtaqlar
Vizualizator
← Məsələlər

BAPC21-073.Decelerating Jump

Medium · 3 s · 256 MB

  • icpc
  • bapc
  • 2021

An athlete is participating in a new sport that is the perfect mix of hopscotch and triple jumping. For this jury sport, nnn 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.

Giriş formatı

The input consists of:

• One line with an integer nnn (2≤n≤30002\leq n\leq 30002≤n≤3000), the number of squares.

• One line with nnn integers p1,p2,…,pnp_1, p_2, \dots, p_np1​,p2​,…,pn​ (−109≤pi≤109-10^9\leq p_i\leq 10^9−109≤pi​≤109), the number of points the jury awards for jumping on each of the squares.

Çıxış formatı

Output the maximum score that an athlete can get.

Qeyd

Source: Benelux Algorithm Programming Contest 2021 · Author: Onno Berrevoets · License: CC BY-SA 4.0 · Original: https://bapc.eu · Statement adapted for AlgoLens and shared under the same license.

Nümunələr

Giriş #1

4
1 -1 1 1

Çıxış #1

3

Giriş #2

4
1 1 -1 1

Çıxış #2

2

Giriş #3

3
-1 1 -1

Çıxış #3

-1

Giriş #4

3
-1 -1 -1

Çıxış #4

-2