Cat-astrophe
You have a weakness for adopting cats from the local pet shelter. Every time you walk by, you impulsively adopt another one, until you've adopted cats in total. Each cat has an associated daily cost of
dollars for food and other essentials.
After some time, you decide to reflect on your total daily spending. You are given queries, each with a cost threshold
. For each query, determine the maximum number of cats you can afford, starting from the first one you adopted, such that your cumulative daily cost does not exceed the threshold.
Input
On the first line, you are given two integers and
, where
is the number of cats you've adopted, and
is the number of threshold queries.
On the second line, you are given space-separated positive integers
, where
represents the cost of the
th cat.
On the third line, you are given space-separated non-negative integers
, where
represents the
th threshold.
Output
For each query, print one number, each on its own line.
Examples
Input 1
4 3
2 4 3 5
2 8 1
Output 1
1
2
0
Explanation
Query 1:
- Threshold
- After
cat, the total daily spend is
. Thus we output
cat.
Query 2:
- Threshold
- After
cats, the total daily spend is
. Thus we output
cats. If we were to include the third cat, we would exceed our threshold.
Query 3:
- Threshold
- No number of cats will allow us to spend less than
. Thus we output
.
Comments