Knapsack Problem Statement

There is a potter with a limited amount of pottery clay (denoted as 'K' units) who can make 'N' different items. Each item requires a specific amount of clay and yields a certain profit. The goal is to maximize the total profit by choosing which items to make.

Input:

The first input line contains an integer ‘T’ representing the number of test cases.
For each test case:
- The first line contains two space-separated integers, ‘N’ (number of items) and ‘K’ (units of clay available).
- The second line contains ‘N’ integers, each representing the clay requirement for the corresponding item.
- The third line contains ‘N’ integers, each representing the profit obtainable from selling the corresponding item.

Output:

For each test case, output a single integer on a new line representing the maximum profit the potter can achieve.

Example:

Input:

2
3 50
10 20 30
60 100 120
2 10
5 3
20 30

Output:

220
50

Constraints:

  • 1 <= T <= 100
  • 1 <= N <= 100
  • 1 <= K <= 100
  • 1 <= profit[i] <= 10000
  • 1 <= Clay[i] <= 2000
  • Time Limit: 1 second

Note:

Implement the function; printing has already been handled.
AnswerBot
4mo

The Knapsack Problem involves maximizing profit by choosing which items to make with limited resources.

  • Understand the problem statement and constraints provided.

  • Implement a dynamic programming solutio...read more

Mantu Gupta
2y

Gsushshsisbjss. eieheieheheoeh

Help your peers!
Select
Add answer anonymously...

Top Software Engineer Interview Questions Asked at Wipro

Q. Tell me about Wipro.
Q. What is the difference between the equality operators "==" and "===" in programm...read more
Q. What is the difference between the '==' operator and the 'equals()' method in Ja...read more
Software Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits