#C10524. Minimize Total Risk

    ID: 39739 Type: Default 1000ms 256MiB

Minimize Total Risk

Minimize Total Risk

In this problem, you are given (n) patients and (m) doses of a vaccine. Each patient has an associated risk factor. Your task is to administer exactly (m) doses to patients such that the total risk factor is minimized. In other words, you need to select the (m) patients with the lowest risk factors and output the sum of these risk factors. Mathematically, if the sorted list of risk factors is (a_1 \leq a_2 \leq \dots \leq a_n), then the answer is (\sum_{i=1}^{m} a_i).

inputFormat

The first line contains two integers (n) and (m) ((1 \leq m \leq n)), where (n) is the number of patients and (m) is the number of available doses. The second line contains (n) space-separated integers, where each integer represents the risk factor of a patient.

outputFormat

Output a single integer, which is the minimum total risk factor achievable by administering exactly (m) doses.## sample

5 3
3 1 2 5 4
6