#C9726. Unique Sum of Integers Below a Threshold
Unique Sum of Integers Below a Threshold
Unique Sum of Integers Below a Threshold
You are given a list of integers (a) and an integer threshold (k). Your task is to compute the sum of all unique integers in (a) that are less than or equal to (k).
More precisely, let (S) be the set of unique values in (a). The answer is defined as
[
\text{answer} = \sum_{x \in S,; x \le k} x
]
If there is no integer in (S) less than or equal to (k), the answer is (0).
This problem tests your ability to handle duplicates using data structures such as sets and implement input/output operations via standard input and output.
inputFormat
The first line contains two space-separated integers: (n) (the number of elements in the list) and (k) (the threshold).
The second line contains (n) space-separated integers representing the list (a).
outputFormat
Output a single integer representing the sum of all unique integers from the list (a) that are less than or equal to (k).## sample
5 3
1 2 2 3 4
6