Thinh loves candy very much and he is playing a game with candies. He has N candies numbered 1 to N from left to right. The i-th candy has a value A[i]. He wants to eat these candies one by one such that he can maximize the total points after eating all of them. The total points of eating candies are calculated as follows: • Whenever Thinh eats one candy, this candy will disappear and he will get an amount of points equal to the product of the value of it and the smaller value between 2 nearest candies to the left and right of it. • If there is no candy on the left or on the right, its value is assumed to be 1.Let's help Thinh find the optimal way to eat these candies.
đang được dịch, vui lòng đợi..
