← 返回 meta 的题目列表Sum of Iterative Reduction Steps
类型:online_judge
Given an integer array, repeatedly find the first non-zero value from the left, record it, and then iterate to the right. Check each element; stop if the element is less than the recorded value, or subtract the recorded value if the element is greater than or equal. After each complete pass, add the recorded value to an answer list. Repeat this until the entire array is reduced to zeros. Finally, return the sum of all numbers in the answer list.
Example
Input
3 0 2 0 1 0 0