#K6476. Maximum Sum After Operations
Maximum Sum After Operations
Maximum Sum After Operations
You are given an array of integers of length , and an integer which represents the number of allowed operations. In one operation, you can update any element of the array to any value. Under the assumption that if , you can transform the entire array so that each element becomes the maximum element present in the original array, compute the maximum possible sum of the array after performing at most operations. Note that if , no changes can be made and the sum of the array is simply , whereas if , the optimal sum is .
For example, if the array is [1, 2, 3, 4] and , the maximum sum obtainable is .
inputFormat
The input is given in two lines. The first line contains two integers and , where is the number of elements in the array and is the number of operations allowed. The second line contains space-separated integers representing the elements of the array.
outputFormat
Output a single integer representing the maximum possible sum of the array after performing at most operations. If , output , and if , output .## sample
4 2
1 2 3 4
16