Rolling a Snowball
Time limit1sMemory limit1024 MB
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 , and snow has piled up only from position to position . At position , there is of snow. The contest rule is to roll a snowball in the front yard for seconds to build a snowman. The snowball starts with size at position .
Susu, who wants to build the biggest snowman, studied how to roll a snowball. Rolling or throwing the snowball takes 1 second.
- Roll the snowball to the current position +1. If the current position is , the snowball's size increases by .
- 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 , its size increases by . Any fractional part is truncated. Even if the snowball's size becomes 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 () and the contest time (), separated by a space.
The second line gives a sequence of length . ()
Output
On the first line, print the largest snowball size achievable within the contest time.