This page is still under construction.

Parts of this page are still being built. What you see may change.

Dao and Dizzy's Date

Time limit1sMemory limit1024 MB

Summary
Walk on a line of N places for T minutes starting and ending at place 1, gaining h[j] whenever you move to place j, and maximize total happiness.
Level

Hard8 of 10

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

Problem

The new year has come to Bubble Hill in Crazy Park. To celebrate, Dao and Dizzy are going on a date and plan to look around Bubble Hill.

Bubble Hill consists of NN places connected in a straight line. There are N−1N-1 roads linking pairs of places: for each integer ii from 11 to N−1N-1, place ii and place i+1i+1 are connected by a road.

Dao and Dizzy plan their date minute by minute. Each minute they choose one of the following three actions.

  • If they are at place ii with 2≤i≤N2 \leq i \leq N, they take a road to place i−1i-1.
  • If they are at place ii with 1≤i≤N−11 \leq i \leq N-1, they take a road to place i+1i+1.
  • They stay where they are.

Each minute, Dao and Dizzy gain happiness depending on the place ii they were at one minute earlier and the place jj they are at now. If i≠ji \neq j, they gain h_jh\_j happiness. The value h_jh\_j may be negative, which means they lose −h_j-h\_j happiness. If i=ji = j, their happiness does not change.

Only TT minutes remain for the date, so they want to start from the village, make their happiness as large as possible, and come back. That is, the starting and ending place must always be village 1, where Dao and Dizzy live. Find the happiness Dao and Dizzy will gain.

Input

The first line gives two integers NN and TT. (2≤N≤100 0002 \le N \le 100\,000, 1≤T≤1091 \le T \le 10^{9})

The second line gives NN integers separated by spaces; the ii-th number is h_ih\_i. (−109≤h_i≤109-10^9 \le h\_i \le 10^9, h_1=0h\_1 = 0)

Output

Print the maximum happiness Dao and Dizzy can gain on this date.

Examples2

  1. Example 1

    Input
    5 6
    0 6 -2 9 3
    
    Expected output
    18
    
  2. Example 2

    Input
    5 11
    0 6 -2 9 3
    
    Expected output
    41