Candy
InterviewTime limit1sMemory limit256 MB
Pack J candies using the fewest boxes by filling the largest capacity boxes first.
Problem
You own a candy factory. Every day you pack candies into boxes and send them to the store.
The factory has boxes, and their sizes can differ. You want to use as few boxes as possible. A box does not have to be filled completely, so a partly filled box is fine.
Read the number of candies and the size of every box, then print the smallest number of boxes that holds all of the candies. The boxes are guaranteed to have enough room for all of the candies.
Input
The first line contains the number of test cases (). Each test case has the form below.
The first line of a test case contains the number of candies and the number of boxes ().
Each of the next lines contains the height and the width of the -th box (). Two boxes may have the same size. One box holds at most candies.
Output
Print lines. On each line print the smallest number of boxes needed for the -th test case.