#K691. Minimum Bonus Distribution
Minimum Bonus Distribution
Minimum Bonus Distribution
Given the performance ratings of a set of employees, you are required to determine the minimum number of bonus points that must be distributed under the following rules:
- Each employee must receive at least 1 bonus point.
- If an employee has a higher rating than their immediate neighbor, they must receive more bonus points than that neighbor.
The ratings are given as an array of integers. Your task is to compute the smallest total number of bonus points needed so that the above conditions are satisfied.
Mathematical Formulation:
Let \( r_1, r_2, \dots, r_n \) be the ratings array, and let \( b_1, b_2, \dots, b_n \) be the bonus distribution such that \( b_i \ge 1 \) for all \( i \) and:
[ \text{if } r_i > r_{i-1} \text{ then } b_i > b_{i-1} \quad \text{and} \quad \text{if } r_i > r_{i+1} \text{ then } b_i > b_{i+1}. ]
Compute ( \sum_{i=1}^{n} b_i ) minimized under these conditions.
inputFormat
The input is given via stdin and has the following format:
n r1 r2 r3 ... rn
Here, n
is the number of employees, and the next line contains n
space-separated integers representing the performance ratings of each employee.
outputFormat
Output to stdout a single integer: the minimum total number of bonus points required.
## sample3
1 0 2
5
</p>