CodeLab Academy 📞 9936 6696
← List Python · Level 10: Algorithms Code · 100 points ← #910 #912 →

#911. Knapsack (0/1)

You have a backpack that can hold weight W, and n items (weight, value). Find the largest total value you can take without the total weight going over W. ### Input The first line has n W, then n lines `weight value`. ### Output A number.

Examples

Input
2 16
15 35
20 61
Output
35
Input
4 34
20 70
1 96
15 48
3 89
Output
255

💡 You can solve it with Python, JavaScript or blocks. Read the input line by line with input(). Don't print a question (like input("Number: ")). Print exactly what the output asks for, nothing more.

🔒 You can solve the first 3 problems without an account. Sign up for free to solve this one!