Around the world
Time limit5sMemory limit24 MB
For each plane range, find the fewest refueling landings to circle all airports from the best start, or report impossible.
- Level
Medium7 of 10
- Topics
- Greedy, Prefix sum, Two pointers
- Solved
- No attempts yet
Problem
After years of trying, Byteasar finally earned a pilot license. To celebrate it he decided to buy an airplane and fly once around 3-SATurn, the planet he lives on. The route follows the equator. The equator is long, so the plane has to refuel on the way. There are airports along the equator, and the plane fills its tank every time it lands at one. Each plane model has its own flight range, the greatest distance it covers on a full tank without landing.
For each of the models he is considering, Byteasar wants the smallest number of landings needed to fly around the equator. The final landing counts too. He may pick a different starting airport for each model.
Input
The first line contains the number of airports and the number of plane models , separated by a single space (, ).
The second line contains the distances between neighbouring airports , separated by single spaces. is the distance between airport and airport , and is the distance between airport and airport . Every is a positive integer, and .
The third line contains the flight ranges , separated by single spaces (). is the greatest distance the -th model flies before it has to land and refuel. All distances are given in kilometres.
Output
Print lines. Line contains the minimum number of flight legs needed to fly the -th model once around 3-SATurn along the equator. The number of flight legs equals the number of landings, and the journey may start at any airport. If the -th model cannot complete the journey, print NIE, the Polish word for "no".
Hint

The picture shows the airports of the first example. The thick solid line is an optimal route for the plane with flight range 4, and the dotted line is an optimal route for the plane with flight range 3.