This page is still under construction.

Parts of this page are still being built. What you see may change.

Around the world

Time limit5sMemory limit24 MB

Summary
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 nn 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 ss 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 nn and the number of plane models ss, separated by a single space (2≤n≤1062 \le n \le 10^6, 1≤s≤1001 \le s \le 100).

The second line contains the distances between neighbouring airports l1,l2,…,lnl_1, l_2, \dots, l_n, separated by single spaces. lil_i is the distance between airport ii and airport i+1i+1, and lnl_n is the distance between airport nn and airport 11. Every lil_i is a positive integer, and l1+l2+⋯+ln≤109l_1 + l_2 + \dots + l_n \le 10^9.

The third line contains the flight ranges d1,d2,…,dsd_1, d_2, \dots, d_s, separated by single spaces (1≤di≤l1+l2+⋯+ln1 \le d_i \le l_1 + l_2 + \dots + l_n). did_i is the greatest distance the ii-th model flies before it has to land and refuel. All distances are given in kilometres.

Output

Print ss lines. Line ii contains the minimum number of flight legs needed to fly the ii-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 ii-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.

Examples4

  1. Example 1

    Input
    6 4
    2 2 1 3 3 1
    3 2 4 11
    
    Expected output
    4
    NIE
    3
    2
    
  2. Example 2

    Input
    3 1
    3 4 3
    6
    
    Expected output
    2
    
  3. Example 3

    Input
    2 3
    1 1
    1 2 2
    
    Expected output
    2
    1
    1
    
  4. Example 4

    Input
    7 4
    1 1 1 1 1 1 1
    1 2 3 7
    
    Expected output
    7
    4
    3
    1