#C2954. Minimum Bonuses Distribution

    ID: 46327 Type: Default 1000ms 256MiB

Minimum Bonuses Distribution

Minimum Bonuses Distribution

You are given a group of employees with their performance ratings. Each employee must receive at least one bonus unit. In addition, if an employee has a higher rating than an adjacent employee, they must receive more bonuses than that neighbor.

Formally, let \(N\) be the number of employees and \(ratings[0 \ldots N-1]\) be an array of integers where \(ratings[i]\) represents the rating of the \(i\)th employee. You must assign each employee a bonus \(bonus[i]\) such that:

  • \(bonus[i] \ge 1\) for all \(i\),
  • If \(ratings[i] > ratings[i-1]\), then \(bonus[i] > bonus[i-1]\), and
  • If \(ratings[i] > ratings[i+1]\), then \(bonus[i] > bonus[i+1]\).

Your task is to compute the minimum total number of bonus units required, i.e., \(\sum_{i=0}^{N-1} bonus[i]\).

inputFormat

The input is given via standard input. The first line contains an integer \(N\) representing the number of employees. The second line contains \(N\) space-separated integers that represent the ratings of each employee.

outputFormat

Output a single integer via standard output, which is the minimum total bonus units required to satisfy the above conditions.

## sample
5
1 2 2 3 1
7

</p>