Problem G
A Question of Ingestion
Stan Ford is a typical college graduate student, meaning
that one of the most important things on his mind is where his
next meal will be. Fortune has smiled on him as he’s been
invited to a multi-course barbecue put on by some of the
corporate sponsors of his research team, where each course
lasts exactly one hour. Stan is a bit of an analytical type and
has determined that his eating pattern over a set of
consecutive hours is always very consistent. In the first hour,
he can eat up to
Stan is waiting to hear what will be served each hour of the
barbecue as he realizes that the menu will determine when and
how often he should refrain from eating. For example, if the
barbecue lasts
The prospect of all this upcoming food has got Stan so frazzled he can’t think straight. Given the number of courses and the number of calories for each course, can you determine the maximum amount of calories Stan can eat?
Input
Input starts with a line containing two positive integers
Output
Display the maximum number of calories Stan can consume.
Sample Input 1 | Sample Output 1 |
---|---|
5 900 800 700 400 300 200 |
2243 |
Sample Input 2 | Sample Output 2 |
---|---|
5 900 800 700 40 300 200 |
1900 |