Dsa
Greedy
Medium
Subscription Plan Selection
A company offers various subscription plans that provide different benefits. Each plan has a price, and your task is to select a combination of plans that offers maximum benefits within a specified budget without exceeding it.
Input:
The first line contains two integers: `M` (maximum budget) and `N` (number of plans available).
The next `N` lines each contain two integers: `B_i` (benefit of the plan) and `P_i` (price of the plan).
Output:
Print a single integer: maximum benefit obtainable without exceeding the budget.
Example:
Input:
100 3
50 50
40 30
30 20
Output:
120
Key concepts
greedyarraysorting
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