You are given an integer array vulnerabilities of length n, where vulnerabilities[i] is the initial security score of server i.
You must perform exactly k operations. In each operation, choose any server i and decrease vulnerabilities[i] by 1.
After all k operations, let the resulting array be final.
Task: Compute the maximum possible value of min(final) that you can achieve by choosing which servers to decrement each time.
Input
-
Integer array
vulnerabilities
(length
n
)
-
Integer
k
(number of operations)
Output
-
An integer: the maximum achievable
min(final)
Notes / Constraints (reasonable interview assumptions)
-
1 ≤ n ≤ 2e5
-
0 ≤ vulnerabilities[i] ≤ 1e9
-
0 ≤ k ≤ 1e12
-
Decrements may make values negative.
Example
-
vulnerabilities = [5, 1, 4]
,
k = 3
-
One optimal strategy is to decrement the
5
three times →
[2, 1, 4]
, so
min = 1
.
-
Output:
1