Submit | All submissions | Best solutions | Back to list |
EI2122Q1M1 - Sum of K distinct Largest |
Given n integers, find the sum of at most k largest distinct values.
Input
- The first line contains two integers n, k (1 ≤ n, m ≤ 105).
- The second line contains n integers (-109 ≤ ai ≤ 109).
Output
The required sum.
Sample
Input |
Output |
10 3 9 5 21 15 16 1 5 1 9 21 |
52 |
10 8 9 5 21 15 16 1 5 1 9 21 |
103 |