#P2234. Revenue Stability Analysis
Revenue Stability Analysis
Revenue Stability Analysis
Tiger, recently promoted as the manager of the sales department, is given his first task: analyzing the company's daily revenue records since its inception. Due to holidays, sales promotions, or other factors, daily revenue may fluctuate. However, sudden large changes might indicate underlying issues in the company's operations.
The minimal fluctuation for a day is defined as follows:
- For the first day, the minimal fluctuation is the revenue of the first day itself.
- For any day i (with i > 1), it is defined by the formula:
The overall stability measure of the company's revenue is the sum of the minimal fluctuation values of all days. Your task is to compute this sum.
inputFormat
The input begins with an integer N
representing the number of days. The following N
integers represent the daily revenue figures. The numbers are separated by spaces or newlines.
outputFormat
Output a single integer: the sum of the minimal fluctuation values for all days.
sample
1
5
5