#C8607. Maximum Magic Intensity
Maximum Magic Intensity
Maximum Magic Intensity
You are given N magical plants, each with a certain power value. You must activate exactly K plants. However, only plants with odd power values contribute to the total magic intensity, while plants with even power values contribute 0
intensity.
The maximum magic intensity is defined as the sum of the highest odd power values among the chosen plants. In other words, if there are M odd-powered plants in the list and you need to choose K plants, then the final intensity is given by:
$$\text{Intensity} = \sum_{i=1}^{\min(K, M)} a_i$$
where \(a_1, a_2, \ldots, a_M\) are the odd power values sorted in descending order. If there are fewer than K odd numbers available, you must nonetheless choose exactly K plants by including some even-powered plants, which do not add any intensity.
Your task is to compute the maximum possible magic intensity.
inputFormat
The first line of input contains two integers, N and K (1 ≤ K ≤ N), where N is the number of magical plants and K is the number of plants to activate.
The second line contains N space-separated integers, representing the power values of the magical plants.
outputFormat
Output a single integer representing the maximum magic intensity after activating exactly K plants.
## sample5 3
3 6 5 2 7
15