100 atcoder#ABC216E. [ABC216E] Amusement Park
[ABC216E] Amusement Park
Score : points
Problem Statement
Takahashi has come to an amusement park. The park has attractions. The fun of the -th attraction is initially .
When Takahashi rides the -th attraction, the following sequence of events happens.
- Takahashi's satisfaction increases by the current fun of the -th attraction.
- Then, the fun of the -th attraction decreases by .
Takahashi's satisfaction is initially . He can ride the attractions at most times in total in any order. What is the maximum possible value of satisfaction Takahashi can end up with?
Other than riding the attractions, nothing affects Takahashi's satisfaction.
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the maximum possible value of satisfaction that Takahashi can end up with.
3 5
100 50 102
502
Takahashi should ride the first attraction twice and the third attraction three times. He will end up with the satisfaction of . There is no way to get the satisfaction of or more, so the answer is .
2 2021
2 3
9
Takahashi may choose to ride the attractions fewer than times in total.