Lunch boxes

3.2

39 votes
Implementation, Basic Programming, Sorting, Basics of Greedy Algorithms, Basics of Implementation
Problem

Alice works as a restaurant manager. The restaurant has prepared N lunch boxes and Alice plans to distribute them to some schools. Consider that there are M schools and an ith school orders Ai lunch boxes.

She wants to distribute lunch boxes to as many schools as possible. Also, she has the following rule:

  • For an ith school, she gives either zero or Ai lunch boxes

Your task is to help Alice to determine the maximum number of schools that can get lunch boxes.

Input format    

  • The first contains an integer t that denotes the number of test cases in the input.
  • Each test case consists of two lines:
    • The first line contains two integers N and M.
    • The second line contains M integers A1,A2,...,Am.

Output format

For each test case, you are required to print one integer that represents the maximum number of schools that can receive lunch boxes.

Constraints

1t10

1N,M105

1Ai106,1iM

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

In first test case 1,3,4 schools got lunch-boxes.

In second test case 3,4 and 2(or 5) schools got lunch boxes.

Editor Image

?