Last Updated: 17 Sep, 2025

Minimum Cars for Group Trip

Moderate
Asked in company
FactSet

Problem statement

You are organizing a group trip and need to transport everyone using a fleet of available cars. You are given the total number of people who need to travel and a list of the seating capacities of the cars you have.

Your task is to determine the minimum number of cars required to transport all the people.


Input Format:
The first line of input contains an integer 'P', the total number of people to transport.

The second line contains an integer 'C', the number of cars available.

The third line contains 'C' space-separated integers, representing the seating capacity of each car.


Output Format:
Print a single integer representing the minimum number of cars required.


Note:
It is guaranteed that the total capacity of all cars is sufficient to accommodate all the people.

The key to this problem is a greedy strategy: to use the fewest cars, you should always pick the available cars with the largest capacities first.