Simple Fun #5: Knapsack Light
Description:
Task
You found two items in a treasure chest! The first item weighs weight1
and is worth value1
, and the second item weighs weight2
and is worth value2
. What is the total maximum value of the items you can take with you, assuming that your max weight capacity is maxW
/max_w
and you can't come back for the items later?
Example
For value1 = 10
, weight1 = 5
, value2 = 6
, weight2 = 4
and maxW = 8
, the output should be 10
.
You can only carry the first item.
For value1 = 10
, weight1 = 5
, value2 = 6
, weight2 = 4
and maxW = 9
, the output should be 16
.
You're strong enough to take both of the items with you.
For value1 = 10
, weight1 = 10
, value2 = 6
, weight2 = 10
and maxW = 9
, the output should be 0
.
Unfortunately, you're not strong enough to take any one :(
Input/Output
Arguments
- integer
value1
- integer
weight1
- integer
value1
- integer
weight1
- integer
maxW
/max_w
Contraints
Output
- integer representing the maximum value of the items that can be carried
Similar Kata:
Stats:
Created | Jan 22, 2017 |
Published | Jan 22, 2017 |
Warriors Trained | 1143 |
Total Skips | 29 |
Total Code Submissions | 2553 |
Total Times Completed | 689 |
JavaScript Completions | 252 |
C# Completions | 86 |
Python Completions | 302 |
PHP Completions | 55 |
Ruby Completions | 45 |
Crystal Completions | 9 |
Haskell Completions | 6 |
Total Stars | 18 |
% of votes with a positive feedback rating | 89% of 207 |
Total "Very Satisfied" Votes | 167 |
Total "Somewhat Satisfied" Votes | 35 |
Total "Not Satisfied" Votes | 5 |
Total Rank Assessments | 12 |
Average Assessed Rank | 7 kyu |
Highest Assessed Rank | 5 kyu |
Lowest Assessed Rank | 8 kyu |