This page is still under construction.

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

Rolling a Snowball

Time limit1sMemory limit1024 MB

Summary
Starting with size 1 at position 0, each second either step +1 adding a[i+1] or jump +2 halving the size (floor) then adding a[i+2]; maximize the final size within M seconds.
Level

Medium5 of 10

Topics
Dynamic programming, Brute force
Solved
No attempts yet

Problem

A snowman-building contest is held in the front yard of Sookmyung Women's University, a neighborhood where a lot of snow falls. The front yard has length NN, and snow has piled up only from position 11 to position NN. At position ii, there is aia_i of snow. The contest rule is to roll a snowball in the front yard for MM seconds to build a snowman. The snowball starts with size 11 at position 00.

Susu, who wants to build the biggest snowman, studied how to roll a snowball. Rolling or throwing the snowball takes 1 second.

  1. Roll the snowball to the current position +1. If the current position is ii, the snowball's size increases by ai+1a_{i+1}.
  2. Throw the snowball to the current position +2. As it lands, the impact reduces the snowball's size to half of its original size, and if the current position is ii, its size increases by ai+2a_{i+2}. Any fractional part is truncated. Even if the snowball's size becomes 00 after a throw, the snowball does not disappear.

If the snowball reaches the end of the front yard, rolling ends regardless of the remaining time. Write a program that finds the largest snowball size achievable within the contest time.

Input

The first line gives the length of the front yard NN (1≤N≤1001 \leq N \leq 100) and the contest time MM (1≤M≤101 \leq M \leq 10), separated by a space.

The second line gives a sequence aa of length NN. (1≤ai≤1 000 0001 \leq a_i \leq 1\,000\,000)

Output

On the first line, print the largest snowball size achievable within the contest time.

Examples1

  1. Example 1

    Input
    10 5
    1 3 4 5 6 7 8 10 12 14
    
    Expected output
    28