#K6476. Maximum Sum After Operations

    ID: 32047 Type: Default 1000ms 256MiB

Maximum Sum After Operations

Maximum Sum After Operations

You are given an array of integers AA of length nn, and an integer kk 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 k>0k > 0, 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 kk operations. Note that if k=0k = 0, no changes can be made and the sum of the array is simply i=1nAi\sum_{i=1}^{n} A_i, whereas if k>0k > 0, the optimal sum is n×max(A)n \times \max(A).

For example, if the array is [1, 2, 3, 4] and k=2k=2, the maximum sum obtainable is 4×4=164 \times 4 = 16.

inputFormat

The input is given in two lines. The first line contains two integers nn and kk, where nn is the number of elements in the array and kk is the number of operations allowed. The second line contains nn 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 kk operations. If k=0k = 0, output i=1nAi\sum_{i=1}^{n} A_i, and if k>0k > 0, output n×max(A)n \times \max(A).## sample

4 2
1 2 3 4
16