Gourav, our friend wants to set up his telecom company that provides free 5G data to everyone in the city. He started working on his company and saw that the cost of buying new cell towers was very high. He went around the city to find the cell towers that he could rent for his company.
Gourav had to cover the total area of the city. He saw that there were multiple towers in the area in a straight line that can provide signals to everyone within their range of operation. Jeet wanted to launch his company at the earliest and asked for your help.
The city starts at point and ends at the point . There are towers located at points in the city at a distance of unit from the previous point. Each tower located at point has a range capacity that can provide high speed signals to the range. Since, the company is new and has limited funding, you need to find the minimum number of towers Jeet needs to rent, in order to cover the entire city with his high speed 5G network. If there is even 1 spot that cannot be covered, return .
The 1st line contains , the end point
The next line contains the array ranges of size , where element has signal range .
The minimum number of towers to rent, if the entire range cannot be covered, then print -1
The tower at point 0 can cover the range [-3,3] The tower at point 1 can cover the range [-3,5] The tower at point 2 can cover the range [1,3] The tower at point 3 can cover the range [2,4] The tower at point 4 can cover the range [4,4] The tower at point 5 can cover the range [5,5] Renting the second tower at point 1 will ensure connectivity in the entire range [0,5]