#C7105. Minimum Total Bonuses

    ID: 50940 Type: Default 1000ms 256MiB

Minimum Total Bonuses

Minimum Total Bonuses

You are given N employees and an array of their performance ratings. Each employee must receive at least one bonus. In addition, if an employee has a higher rating than his or her adjacent neighbor, then the employee must receive more bonus than that neighbor.

Your task is to compute the minimum total number of bonuses required to satisfy these conditions.

In other words, for an array of ratings \(r[0], r[1], \ldots, r[N-1]\), you need to assign a bonus array \(b[0], b[1], \ldots, b[N-1]\) such that:

  • \(b[i] \ge 1\) for all \(0 \le i < N\), and
  • If \(r[i] > r[i-1]\) then \(b[i] > b[i-1]\) and if \(r[i] > r[i+1]\) then \(b[i] > b[i+1]\).

Determine the minimum sum of the bonuses \(\sum_{i=0}^{N-1} b[i]\) that meets these requirements.

inputFormat

Input Format:

  • The first line contains a single integer, \(N\), the number of employees.
  • The second line contains \(N\) space-separated integers representing the ratings of the employees.

outputFormat

Output Format:

  • Output a single integer representing the minimum total bonuses required.
## sample
5
1 2 2 5 1
7