🐾 Cross the Threshold
There are n particles present in a space and an array, initialEnergy[n]. The
finalEnergy[i] of the ith particle is max(initialEnergy[i] - barrier, 0).
The goal is to find the maximum possible integer value of the barrier such that the sum of final energies of the
particles is greater than or equal to a given threshold th.
Complete the function getMaxBarrier in the editor.
getMaxBarrier has the following parameter(s):
- 1.
int initialEnergy[n]: the initial energies of the particles - 2.
int th: the threshold
Returns
int: the maximum integer value of the barrier such that the sum of energies of
all the particles is greater than or equal to th
1Example 1

2Example 2
3Example 3

Constraints
Limits and guarantees your solution can rely on.
2 ≤ n ≤ 105
1 ≤ initialEnergy[i] ≤ 109
1 ≤ th ≤ 1014
It is guaranteed that a non-negative value of barrier will exist in each case, i.e., ∑initialEnergy[i] for all i from 0 to n-1 is greater than or equal to threshold th.