Time on Task
Time limit1sMemory limit128 MB
Given a time limit and chore durations, find the largest number of chores that can be completed in any order.
Problem
A parent has asked you to do your chores.
Each chore takes a certain amount of time, and you can only do one chore at a time. The time you are given may not be enough to finish every chore. You may do the chores in any order you like.
Determine the largest number of chores you can finish within the given amount of time.
Input
The first line contains an integer (), the total number of minutes you have available for your chores.
The second line contains an integer (), the number of chores you may choose from. Each of the next lines contains a positive integer: the number of minutes needed for that chore. Each chore takes at most minutes.
Output
Output the maximum number of chores that can be finished within the time limit .
Hint
For example, suppose the time limit is minutes and there are chores taking , , and minutes. The answer is , because only two chores (the first and the third) can be finished within minutes, and it is impossible to finish all three.