Dsa
Greedy
Medium
Vacation Budget Allocation
You are planning a vacation with a set budget and a list of activities, each with a cost and a fun factor. Your goal is to maximize the fun while staying within budget. For each activity, you can only choose to participate in it or not. Write a program that reads the budget, the number of activities, and their respective costs and fun factors, and calculates the maximum fun you can achieve.
Input format:
- The first line contains an integer B (1 ≤ B ≤ 10^6), the budget for the vacation.
- The second line contains an integer N (1 ≤ N ≤ 1000), the number of activities.
- The next N lines each contain two integers C (1 ≤ C ≤ 10^6) and F (1 ≤ F ≤ 100) representing the cost and fun factor of each activity.
Output format:
- A single integer representing the maximum fun achievable within the budget.
Example:
Input:
50
3
20 30
10 20
30 40
Output:
50
Key concepts
greedybudgetingplanning
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