Dsa
Math
Hard
Weighted Item Selection
You are given a list of items, each with a weight and a value. Your goal is to select a subset of these items such that the total weight does not exceed a given limit while maximizing the total value. The input format is as follows: the first line contains an integer N (the number of items), the second line contains the limit W, followed by N lines each containing two integers: weight and value of an item. Output the maximum total value that can be achieved without exceeding the weight limit.
Example:
Input:
3
50
10 60
20 100
30 120
Output:
220
Key concepts
combinatoricsoptimizationdynamic programming
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