ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules

2185. Journey to the Treasure

Time limit: 1.5 second
Memory limit: 512 MB
On a mysterious island, Captain Flint left a treasure map, which contains clues in the form of a sequence of numbers — an array a. The pirates have a starting value x that they need to transform by following all the steps on the map to reach the treasure.
For each value of x that they choose, the pirates go through the array a from start to finish and perform the following actions for each element of the array:
  1. If the current value x < 0, they add the current element of the array to x.
  2. If x ≥ 0, they subtract the current element of the array from x.
Thus, at the end of the route, the value of x becomes a new number indicating the location of the treasure.
Unfortunately, the pirates turned out to be very weak in mathematics (although they can count bottles of rum perfectly), so they asked you for help in finding the treasure. They have q numbers, possible starting values of x. You need to output for each of these numbers the result obtained after performing the actions described above.
Problem illustration

Input

The first line contains 2 integers n, q — the number of elements in the array a and the number of possible starting values (1 ≤ n, q ≤ 106).
The second line contains n integers separated by spaces, defining the array a. (|ai| ≤ 106).
In the following q lines, each contains one integer xi — the possible starting values. (|xi| ≤ 106).

Output

Output q lines. In the i-th line, output a single number — the number obtained after performing all actions on the number xi.

Samples

inputoutput
3 2
3 1 2
4
-3
-2
1
3 4
2 1 4
10
-5
2
6
3
2
3
-1
Problem Author: Artyom Stepanov, Artyom Abaturov
Problem Source: Ural School Programming Contest 2024