Talent Show
InterviewTime limit1sMemory limit1024 MB
Given N skill levels, arrange the soldiers so that the first full skill plus each rise over the previous performer totals as much as possible.
Problem
Lunar New Year is here, so the unit is holding a talent show! The show runs in order, with one soldier performing at a time.
The show's chief organizer was planning the event based on each soldier's skill. The organizer worried that if the performer before was too good, the next performer would feel pressure and fail to show their real ability. So the organizer made this hypothesis. Let the skill levels in order be . For every with , the -th performer can show only of their skill. The soldier who performs first shows their full skill.
Under this hypothesis, the organizer wants to arrange the soldiers so that the total skill they can show is as large as possible. Find the maximum total skill that all soldiers can show when they are arranged in a suitable order.
Input
The first line contains the number of soldiers .
The second line contains the skill levels of the soldiers, separated by spaces.
Output
Print the maximum total skill that the soldiers can show when they are arranged in a suitable order.