#P2858. [USACO06FEB] Treats for the Cows G/S
[USACO06FEB] Treats for the Cows G/S
Description
FJ has purchased yummy treats for the cows who get money for giving vast amounts of milk. FJ sells one treat per day and wants to maximize the money he receives over a given period time.
The treats are interesting for many reasons:The treats are numbered and stored sequentially in single file in a long box that is open at both ends. On any day, FJ can retrieve one treat from either end of his stash of treats.Like fine wines and delicious cheeses, the treats improve with age and command greater prices.The treats are not uniform: some are better and have higher intrinsic value. Treat has value . Cows pay more for treats that have aged longer: a cow will pay for a treat of age . Given the values of each of the treats lined up in order of the index in their box, what is the greatest value FJ can receive for them if he orders their sale optimally?
The first treat is sold on day and has age . Each subsequent day increases the age by .
Input Format
Line : A single integer, .
Lines : Line contains the value of treat .
Output Format
Line : The maximum revenue FJ can achieve by selling the treats.
5
1
3
1
5
2
43
Hint
Explanation of the sample:
Five treats. On the first day FJ can sell either treat (value ) or treat (value ).
FJ sells the treats (values ) in the following order of indices: , making $1 \times 1 + 2 \times 2 + 3 \times 3 + 4 \times 1 + 5 \times 5 = 43$.
京公网安备 11011102002149号