## SAC '21 P2 - Littering

View as PDF

Points: 5 (partial)
Time limit: 1.0s
Memory limit: 256M

Authors:
Problem type

Ever since , there has been a noticeable increase in the amount of garbage strewn across SAC. The garbage is of concern to Mr. DeMello, who cannot bear the smell. There is also a rumour going around school saying that Mr. DeMello might cancel the final exam if he is happy enough. In order to make Mr. DeMello happy, you decide to clean up some of the garbage. However, Mr. DeMello has a Suck-Up™ Sensor, which will alert him that you are trying to suck up to him after you pick up more than pieces of garbage out of the littered across campus (and make him keep the final exam). Additionally, each piece of garbage has been judged by Mr. DeMello to have a filthiness value, . Armed with this knowledge, you want to find the maximum amount of filthiness you can pick up to maximize your chances to please Mr. DeMello.

#### Input Specification

The first line will contain and , the number of pieces of garbage and the number of pieces of garbage you can pick-up.

The second line will contain space-separated integers, , the filthiness of the piece of garbage.

#### Output Specification

Output the maximum amount of filthiness you can remove from the campus.

5 2
3 4 2 1 5

9

#### Explanation for Sample Output

The best solution is to pick-up the and piece of garbage, yielding the sum of .