#C4923. Maximum Array Sum with K Operations
Maximum Array Sum with K Operations
Maximum Array Sum with K Operations
You are given an array of n integers A and a positive integer K. Your task is to perform exactly K operations. In each operation, you add the maximum element in the array to the total sum. The final answer is the sum of all the original elements plus K times the maximum element in the array.
In other words, if the array is \(A = [A_1, A_2, \dots, A_n]\), then the answer is:
[ \text{Answer} = \sum_{i=1}^{n}A_i + K \times \max(A) ]
Please note that K operations must be performed even if the maximum element is negative.
inputFormat
The input is given via standard input and consists of two lines:
- The first line contains two space-separated integers n and K where n is the number of elements in the array.
- The second line contains n space-separated integers representing the array A.
outputFormat
Output a single integer: the maximum sum after performing exactly K operations, computed as \(\sum_{i=1}^{n} A_i + K \times \max(A)\).
## sample4 1
1 2 3 4
14