Dsa
Greedy
Hard
Meal Distribution for Event
You are organizing a charity meal where you need to distribute meals to guests based on their dietary restrictions. Each guest can have a specific dietary value they can safely consume, and meals have their own dietary values. Your aim is to maximize the number of meals served without exceeding the guest's dietary value. You will read the maximum dietary value of guests and a list of meal dietary values. Output the total number of meals distributed.
Input Format:
The first line contains an integer D (1 <= D <= 10^5) - the maximum dietary value allowable for meals.
The second line contains an integer M (1 <= M <= 10^5) - the number of meals available.
The third line contains M space-separated integers representing the dietary values of the meals.
Output Format:
Print a single integer representing the maximum number of meals that can be served.
Example:
Input:
40
4
30 20 10 50
Output:
3
Key concepts
greedysortingarrays
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now