#K95907. Maximum Sweetness

    ID: 38967 Type: Default 1000ms 256MiB

Maximum Sweetness

Maximum Sweetness

Problem Description: You are given n ingredients, each with a certain sweetness value. Your task is to select exactly k ingredients to maximize the total sweetness of a cake. The total sweetness is defined as the sum of the sweetness values of the chosen ingredients.

Formally, given integers \(n\) and \(k\), and a list of integers \(a_1, a_2, \dots, a_n\) representing the sweetness values, determine the maximum possible sum obtainable by choosing exactly \(k\) ingredients. Note that the sweetness values may be negative, and you must choose exactly \(k\) ingredients regardless.

inputFormat

Input Format:

  • The first line contains two integers \(n\) and \(k\): the number of ingredients and the number of ingredients to choose, respectively.
  • The second line contains \(n\) space-separated integers representing the sweetness values of the ingredients.

outputFormat

Output Format:

Output a single integer that represents the maximum possible total sweetness value by selecting exactly \(k\) ingredients.

## sample
5 3
1 2 5 8 3
16