Under construction

Still being built. Things may change

A Question of Ingestion

Interview

Time limit2sMemory limit512 MB

Summary
Given n hourly courses with calorie counts, maximize total calories eaten when the per-hour limit starts at m, shrinks to two thirds while eating, and resets after two skipped hours.
Level

Medium6 of 10

Topics
Dynamic programming, Greedy, Math, Implementation
Solved
No attempts yet

Problem

Stan is a graduate student, so the question on his mind is where the next meal comes from. The corporate sponsors of his research team invited him to a barbecue with several courses, and each course lasts exactly one hour.

Stan's appetite over consecutive hours follows a fixed rule. In the first hour he can eat up to mm calories. For every hour he keeps eating, that limit drops to two thirds of the previous hour's limit, truncating any fraction of a calorie. If he stops eating for one hour, then in the next hour he can eat at the same limit he had before he stopped. If he stops for two hours in a row, then in the hour after that his limit is mm again and the decrease starts over.

Take m=900m = 900. Eating for five hours in a row gives hourly limits 900, 600, 400, 266, 177. Skipping the third hour gives 900, 600, 0, 600, 400. Skipping both the third and the fourth hour gives 900, 600, 0, 0, 900.

In each hour he eats, Stan consumes the smaller of that hour's limit and the calories of the course served in that hour. Eating a course that is smaller than the limit still counts as eating, so the limit drops all the same. Which hours are worth skipping therefore depends on the menu.

Given the number of courses and the calories of each course, find the largest total number of calories Stan can eat.

Input

The first line contains two positive integers nn and mm separated by a space, the number of courses and the calorie limit for the first hour, with n≤100n \le 100 and m≤20000m \le 20000.

The second line contains nn positive integers, the calories of each course in the order they are served.

Output

Print the maximum number of calories Stan can eat.

Examples2

  1. Example 1

    Input
    5 900
    800 700 400 300 200
    
    Expected output
    2243
    
  2. Example 2

    Input
    5 900
    800 700 40 300 200
    
    Expected output
    1900