Problem Description: Lian raises a pig and wants to sell it to the market. The pigs on the market need to have quality assurance, at least m kg. He has n bags of feed to feed the pigs, and the weight of each bag is a kg. If pig eats more than one bag per day, their absorption will start to decrease, the second bag-1, the third bag -2, and so on. How many days does it take Lian at least to get his pig up to standard?
Input: First line has two integers n, m. Second line has n integers represents dr.
Output: Print how many days does it take Lian at least to get his pig up to standard. If Lian cannot get his pig up to standard anyway, print -1.
Input 1: 5 5 1 1 1 1 1
Output 1: 5
Input 2: 10 40 5 5 5 5 5 5 5 5 5 5
Output 2: 4
Input 3: 10 56 1 2 3 4 5 6 7 8 9 10
Output 3: -1
- Constraints: 1 <= n <= 200000, m is in int range, 1 <= a <= 10000
This is a problem about greedy algorithm and binary search algorithm, I can only think of the greedy part: feed bags with larger weights first, but I don't understand the binary search part.