#K55812. Minimum Rewards Distribution
Minimum Rewards Distribution
Minimum Rewards Distribution
You are given n students standing in a line and each student has a score represented as an integer. Your task is to distribute rewards to these students according to the following rules:
- Each student must receive at least one reward.
- If a student has a higher score than an adjacent student, then this student must receive more rewards than that neighbor.
Formally, let \(s_i\) be the score of the \(i^{th}\) student and \(r_i\) the number of rewards given. Then for every adjacent pair:
- If \(s_i > s_{i-1}\), then \(r_i > r_{i-1}\).
- If \(s_i > s_{i+1}\), then \(r_i > r_{i+1}\).
Your goal is to determine the minimum total number of rewards required to satisfy these conditions.
inputFormat
The input is read from standard input and consists of two lines:
- The first line contains an integer \(n\), the number of students.
- The second line contains \(n\) integers separated by spaces, representing the scores of the students.
outputFormat
Print a single integer representing the minimum total number of rewards needed.
## sample5
1 2 3 2 1
9
</p>