618. Mark and Score
0
Medium
Once upon a time, there was a young boy named Jack who had a passion for playing games. One day, he discovered a new game called "Mark and Score" that had a fascinating algorithm.
The game involved an array of positive integers, and the objective was to select the smallest unmarked integer, add it to the score, and then mark the chosen element along with its two adjacent elements (if they existed). The game continued until all the elements in the array were marked, and the final score was determined by summing up all the chosen integers.
Jack was eager to try out the game. He was given an array of integers and began playing.
He played the game by selecting the smallest unmarked integer and adding it to the score until all the elements in the array were marked. At the end of the game, he calculated the final score and was thrilled with the result.
Can you calculate the final score given the array?
Input Format
Output Format
Example
Input
Output
Constraints
1 <= arr[i] <= 106
View Submissions
Console