#C11144. Minimum Operations to Reach Threshold
Minimum Operations to Reach Threshold
Minimum Operations to Reach Threshold
You are given an array of N integers and an integer threshold K. In a single operation, you can increase every element of the array by 1. Your task is to determine the minimum number of operations required so that every element in the array is at least K.
This can be formulated as finding the smallest number of operations ops such that:
If all elements are already at least K, then the answer is 0.
Example: For N = 5, K = 10, and array [1, 2, 0, 7, 3]
, the minimum element is 0 and the number of operations needed is 10
(i.e. increase every element 10 times to ensure even the minimum reaches 10).
inputFormat
The input is read from stdin and consists of two lines:
- The first line contains two integers N and K, where N is the number of elements in the array and K is the threshold.
- The second line contains N space-separated integers representing the array.
outputFormat
Output a single integer to stdout — the minimum number of operations required so that every element in the array is at least K.
## sample5 10
1 2 0 7 3
10
</p>