Dsa
Greedy
Easy
Field Trip Budgeting
A school is planning a field trip, and they need to allocate a budget for refreshments. Each type of refreshment has a cost. To maximize the number of types of refreshments they can include, write a program that accepts a budget and costs for each refreshment type, then determines how many different types can be bought within that budget.
Input format:
- The first line contains an integer B (the budget).
- The second line contains an integer T (number of refreshment types).
- The third line contains T space-separated integers (costs of refreshments).
Output format:
- A single integer representing the maximum number of different refreshment types that can be bought.
Example:
Input:
30
6
5 10 15 20 25 30
Output:
3
Key concepts
greedybudgetingarrays
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