#C8692. Maximum Fatigue Reduction
Maximum Fatigue Reduction
Maximum Fatigue Reduction
You are given a route which is divided into N segments. Each segment i has an associated fatigue value f_i. You are allowed to place at most M water stations on these segments. Each water station can reduce the fatigue of the segment it is placed on by at most R units. However, a segment’s fatigue cannot be reduced below 0.
Your task is to determine the maximum total fatigue reduction achievable by optimally placing the water stations. Note that you only get benefit from placing a station in a segment, and the reduction from any station is min(f_i, R).
Mathematical Formulation:
If the fatigue values are sorted in descending order, then the answer is given by:
\[ \text{max\_reduction} = \sum_{i=1}^{\min(M, N)} \min(f_{(i)}, R) \]
where \(f_{(i)}\) denotes the i-th largest fatigue value.
inputFormat
The input is read from stdin and has the following format:
- The first line contains three space-separated integers N, M and R.
- The second line contains N space-separated integers representing the fatigue values of each segment.
outputFormat
Output a single integer to stdout which represents the maximum total fatigue reduction possible.
## sample5 2 100
150 200 250 300 350
200