프로그램 명: apio_sequence
제한시간: 2 초

You are playing a game with a sequence of n non-negative integers. In this game you have to split the sequence into k + 1 non-empty parts. To obtain k + 1 parts you repeat the following steps k times:

  1. Choose any part with more than one element (initially you have only one part ? the whole sequence).
  2. Split it between any two elements to get two new non-empty parts.
Each time after these steps you gain the number of points which is equal to product of sums of elements of each new part. You want to maximize the total number of points you gain.

Note

In the first sample you can gain 108 points by the following way: So, after the steps taken above you get four parts (4), (1,3), (4,0), (2, 3) and gain 52 + 36 + 20 = 108 points.

입력

출력

입출력 예

입력

7 3

출력

108

입력

4 1 3 4 0 2 3

출력

1 3 5
출처:apio2014

[질/답] [제출 현황] [푼 후(0)]
[ 채 점 ] [홈으로]  [뒤 로]