SnowflakeOA #13
Cross the Threshold
Estimated MediumJudge-ready
Topics (AI-labelled)Binary Search
The final energy of each particle is max(energy−barrier,0). Find the largest non-negative integer barrier such that the total energy is ≥th. The original total energy is guaranteed to be ≥th.
Input
The first line contains n th, and the second line contains n energies. 2≤n≤100000, 1≤energy≤10⁹, 1≤th≤10¹⁴.
Output
Output the single integer required by the problem.
Example 1
Input:
5 9
4 8 7 2 1
Output:
3
Example 2
Input:
4 8
5 2 13 10
Output:
7
Example 3
Input:
3 6
3 9 7
Output:
5
Example notes
The answers to the three public examples are, in order: 3; 7; 5. All examples have been verified by independent small-scale enumeration or state search.
Editorial
Loading solution…