#K67607. Closest Popularity Sum
Closest Popularity Sum
Closest Popularity Sum
You are given (n) articles, each with a popularity score. Your task is to select exactly (m) articles such that the sum of their popularity scores is as close as possible to a target value (t). Formally, given integers (n), (m), and (t) along with a list of (n) integers representing the popularity scores, find a subset (S) of (m) articles such that (|\sum_{a \in S} a - t|) is minimized. If there are multiple subsets with the same minimum difference, return the sum from the first such subset encountered by your algorithm. Each article can be chosen at most once.
inputFormat
The input is given via standard input. The first line contains three space-separated integers (n), (m), and (t). The second line contains (n) space-separated integers representing the popularity scores of the articles.
outputFormat
Output a single integer --- the sum of the chosen subset of (m) articles whose total popularity score is closest to (t).## sample
7 3 50
10 20 30 25 5 15 40
50