Sherlock in trouble!

0

0 votes
Binary Search, Easy
Problem

This time Sherlock comes to another problem that he has to shift his house from Birmingham to London. But as we all know that Sherlock never does a task which seems to be easy. So he wants to transfer his luggage.

For that Sherlock needs to order a truck. Now, each truck has some predefined weight W assigned. It means this truck can carry no more than W weights.

Watson asks Sherlock Q queries. In each query, Watson gives W and Sherlock need to answer what is the maximum number of items that he can put on a truck for given W. Help him.

Note: Sherlock knows weights of all items of his luggage initially. 

In short, you are given an array A of N integers, the weights of the items. Then, you are given Q queries, each of which is a weight capacity of a truck. You must print the maximum number of items that can fit on the truck.

 

Input format:

  • The first line contains two integers N and Q. N is the number of items, and Q is the number of weight queries.
  • The next line contains an array A of N integers, the weights of each item.
  • The next Q lines contain one integer each W, the weight capacity of the truck.

Output format:

There should be Q lines of output, the answer to each query.


Constraints:

  • 1 ≤ N ≤ 105
  • 1≤ Ai ≤106
  • 1≤ Q ≤105
  • 0≤ W ≤109

 

Subtasks:

Subtask #1 (30 points) : 1 <= N <= 500

Subtask #2 (70 points) : Original Constraints

Time Limit: 1
Memory Limit: 256
Source Limit:
Editor Image

?