DatabricksOA #9
Leftmost Non-Zero Subtract
估计简单可在线判题
考点(AI 标注)模拟/实现
You are given an array of non-negative integers. Repeatedly find the leftmost nonzero element; with its value x, process the elements from that position to the right one by one, subtracting x from an element only if its current value is at least x; in each round, add x to the total. Once the array is all zeros, output the total.
Standard input/output and this site's supplementary ranges follow this problem's description.
输入格式
The first line contains n, and the second line contains n integers. The source gives the value range 0≤a[i]≤10000; since direct simulation is O(n²), this site narrows n to 1≤n≤1000 so that it finishes within the time limit.
输出格式
Output the total accumulated during the process, as one integer.
样例 1
输入:
5
0 2 2 0 3
输出:
3
样例 2
输入:
3
4 4 0
输出:
4
样例 3
输入:
3
1 2 3
输出:
3