Under construction

Still being built. Things may change

FLEX

Interview

Time limit2sMemory limit512 MB

Summary
Distribute M extra ten-thousand-won units among N days to minimize the sum of squared drops between consecutive daily spends.
Level

Medium5 of 10

Topics
Dynamic programming, Greedy, Array, Prefix sum
Solved
No attempts yet

Problem

These days Inho is under a lot of stress, and for him money is stress relief itself. Perhaps that is why, if he cannot spend today as much as he spent yesterday, he feels a sense of deprivation equal to the square of the difference expressed in ten-thousand-won units. More precisely:

If the spending on day i is a ten-thousand won and the spending on day (i+1) is b ten-thousand won, then on day (i+1):

  1. If a ≤ b, he feels no deprivation.
  2. If a > b, he feels deprivation equal to (a - b)2.

Inho is looking over the expected spending records of his bank account for the next N days. Apart from the expected spending, his account has M ten-thousand won left that he can spend freely. Inho wants to distribute this M ten-thousand won efficiently over his upcoming spending so that the sum of the deprivation he will feel over the next N days (that is, the sum of tomorrow's deprivation, the day after tomorrow's deprivation, ..., and the deprivation N days from now) is minimized. Because the minimum withdrawal unit of this account balance is ten thousand won, the distribution can only be done in ten-thousand-won units. Help Inho feel less deprivation in this hot and humid weather.

Input

The first line contains two natural numbers N and M separated by a space, meaning the number of days to settle and the account balance (in ten-thousand-won units). (1 ≤ N < 1000, 0 ≤ M < 200)

The second line contains N integers C1, C2, ..., CN separated by spaces, meaning the expected cost to spend over N days. (0 ≤ Ci ≤ 10)

Ci means that the cost to spend on day i is Ci ten-thousand won. The cost spent on day 0 is regarded as 0.

Output

On the first line, output the minimum possible total deprivation Inho will feel over the next N days after distributing the account balance over the expected spending for N days.

Hint

The word flex originally means to bend or to loosen up the body as a warm-up, and it also appears in the idiom 'flex your muscles', which means to show off the muscles you gain from exercising.

Recently it is used as slang for showing off material resources such as money rather than muscles as a warm-up.

Examples1

  1. Example 1

    Input
    3 1
    3 2 1
    
    Expected output
    1