#include <iostream>
using namespace std;
int main(){
int N;
// Number of players
cin>>N;
//Integer array containing the scores of players
int scores[50];
for(int i=0;i<N;i++){
cin>>scores[i];
}
int chocolates[50];
// Add 1 chocolate to each player
for (int i = 0; i < N; i++) {
chocolates[i] = 1;
}
// Traverse from left to right
for (int i = 1; i < N; i++) {
if (scores[i] > scores[i - 1])
chocolates[i] = chocolates[i - 1] + 1;
else
chocolates[i] = 1;
}
for (int i = N - 2; i >= 0; i--) {
if (scores[i] > scores[i + 1])
chocolates[i] = max(chocolates[i + 1] + 1, chocolates[i]);
else
chocolates[i] = max(chocolates[i], 1);
}
int totalSum = 0;
// Find total sum
for (int i = 0; i < N; i++) {
totalSum += chocolates[i];
}
totalSum -=3;
cout << totalSum << "\n";
cin>>N;
return 0;
}
Comments
Leave a comment