Determine the maximum possible height of a tower built from a sequence of blocks under simple stacking rules.
You are given a sequence of blocks with different heights. Build a tower by taking blocks in order and applying the rule that each next chosen block must satisfy the tower condition from the previous one.
Your task is to compute the best achievable tower height according to the problem's stacking rule.
This is an implementation-style problem where the key is to process the blocks carefully and track the current best tower state as you scan through the input.
Example 1
Input
5 1 2 3 2 5
Output
5
Explanation
A valid tower can be formed by choosing blocks so that the tracked tower value reaches 5.
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.