#C2549. Taco Best Travel
Taco Best Travel
Taco Best Travel
You are given a list of distances corresponding to available travel stops. You must pick exactly \(k\) stops such that the total distance traveled is maximized while not exceeding a given maximum distance \(M\). If no valid combination of stops exists, output None
.
Problem Statement:
Given a list of \(N\) distances, an integer \(k\) (the number of stops to choose), and a maximum allowed distance \(M\), determine the maximum possible sum of distances by choosing exactly \(k\) stops such that the sum does not exceed \(M\). If no combination meets the criteria, output None
.
Input Format: The input is read from standard input (stdin). The first line contains three space-separated integers: \(N\), \(k\), and \(M\). The second line contains \(N\) space-separated integers representing the distances.
Output Format: Print the maximum achievable distance that satisfies the conditions. If no valid combination exists, print None
.
inputFormat
The first line of input contains three integers (N), (k), and (M) separated by spaces, where (N) is the number of distances, (k) is the number of stops to select, and (M) is the maximum allowed distance. The second line contains (N) space-separated integers representing the distances.
outputFormat
Output a single line containing the maximum sum of distances that is less than or equal to (M) by selecting exactly (k) stops. If no such combination exists, output None
.## sample
5 3 174
50 55 57 58 60
173
</p>