Being a very busy person, you have exactly T time to do some interesting things and you want to do maximum such things.
You are given an array a of integers, where each element indicates the time a thing takes for completion. You want to calculate the maximum number of things that you can do in the limited time that you have.
This is a simple Greedy-algorithm problem. In each iteration, you have to greedily select the things which will take the minimum amount of time to complete while maintaining two variables currentTime and numberOfThings. To complete the calculation, you must:
- Sort the array a in a non-decreasing order.
- Select each to-do item one-by-one.
- Add the time that it will take to complete that to-do item into currentTime.
- Add one to numberOfThings.