#K90477. Maximum Cache Frequency Sum
Maximum Cache Frequency Sum
Maximum Cache Frequency Sum
You are given a cache with a capacity to store at most \(K\) resources and a list of request frequencies for various resources. Your task is to determine the maximum sum of frequencies by selecting at most \(K\) resources. Formally, if the frequency list is \(f_1, f_2, \dots, f_n\), you must choose a subset of size at most \(K\) to maximize the sum \(\sum_{i \in S} f_i\).
Input Format: The first line contains an integer \(K\). The second line contains a sequence of space-separated integers representing the frequencies of each resource request.
Output Format: Print a single integer representing the maximum possible sum.
Note: The answer is obtained by selecting the \(K\) largest frequencies (or all frequencies if there are fewer than \(K\) resources).
inputFormat
The input is given via standard input (stdin) in the following format:
- The first line contains a single integer \(K\), which is the maximum number of resources that can be cached.
- The second line contains a space-separated list of integers which denote the frequencies of the resources.
outputFormat
The output is a single integer printed to standard output (stdout) representing the maximum sum of frequencies achievable by caching at most \(K\) resources.
## sample3
20 10 30 40 50
120
</p>