{"id":"5c237133-b452-44fd-b8cf-04b274a04d3f","name":"Fractional Knapsack - Official","description":"1. You are given a number n, representing the count of items.\r\n2. You are given n numbers, representing the values of n items.\r\n3. You are given n numbers, representing the weights of n items.\r\n3. You are given a number \"cap\", which is the capacity of a bag you've.\r\n4. You are required to calculate and print the maximum value that can be created in the bag without overflowing it's capacity.\r\nNote1 -> Items can be added to the bag even partially. But you are not allowed to put same items again and again to the bag.","inputFormat":"A number n\r\nv1 v2 .. n number of elements\r\nw1 w2 .. n number of elements\r\nA number cap","outputFormat":"A decimal number representing the maximum value that can be created in the bag without overflowing it's capacity","constraints":"1 &lt;= n &lt;= 20\r\n0 &lt;= v1, v2, .. n elements &lt;= 50\r\n0 &lt; w1, w2, .. n elements &lt;= 10\r\n0 &lt; cap &lt;= 10","sampleCode":{"cpp":{"code":"#include<bits/stdc++.h>\r\nusing namespace std;\r\n\r\nint main(){\r\n \r\n}"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n\t\r\n\tpublic static void main(String[] args) {\r\n\t\tScanner scn = new Scanner(System.in);\r\n\t\tString str = scn.next();\r\n \r\n\t}\r\n\r\n}"},"python":{"code":"print()"}},"points":10,"difficulty":"easy","sampleInput":"10\r\n33 14 50 9 8 11 6 40 2 15 \r\n7 2 5 9 3 2 1 10 3 3 \r\n5","sampleOutput":"50.0","questionVideo":"","hints":[],"associated":[{"id":"79f25fd1-2a3b-420d-a05b-9fab8397566e","name":"Another name for Merkel-Hellman cryptosystem is","slug":"another-name-for-merkel-hellman-cryptosystem-is","type":4},{"id":"ba70b7b5-3b50-43af-97e9-05e904574b20","name":"What is the time complexity of Fractional Knapsack","slug":"what-is-the-time-complexity-of-fractional-knapsack","type":4},{"id":"bb5bb0c6-7cba-4186-809c-4564a3a2569d","name":"DP optimizes the solution by taking advantage of which of the following:","slug":"dp-optimizes-the-solution-by-taking-advantage-of-which-of-the-following","type":4}],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"52d62581-1313-45fb-aaf0-1d72a45f6a50","name":"Dynamic Programming And Greedy For Beginners","slug":"dynamic-programming-and-greedy-for-beginners","type":0},{"id":"0c2e4b9f-9e33-4dee-b160-8dd57aad6038","name":"Fractional Knapsack - Official","slug":"fractional-knapsack-official","type":1}],"next":{"id":"799a3962-2b02-4700-8a7c-0047d8858c55","name":"Fractional Knapsack - Official","type":3,"slug":"fractional-knapsack-official"},"prev":{"id":"0802c91b-a2f7-4ae7-a4ba-0a3199e2afb4","name":"Unbounded Knapsack","type":3,"slug":"unbounded-knapsack"}}}

Fractional Knapsack - Official

1. You are given a number n, representing the count of items. 2. You are given n numbers, representing the values of n items. 3. You are given n numbers, representing the weights of n items. 3. You are given a number "cap", which is the capacity of a bag you've. 4. You are required to calculate and print the maximum value that can be created in the bag without overflowing it's capacity. Note1 -> Items can be added to the bag even partially. But you are not allowed to put same items again and again to the bag.

{"id":"5c237133-b452-44fd-b8cf-04b274a04d3f","name":"Fractional Knapsack - Official","description":"1. You are given a number n, representing the count of items.\r\n2. You are given n numbers, representing the values of n items.\r\n3. You are given n numbers, representing the weights of n items.\r\n3. You are given a number \"cap\", which is the capacity of a bag you've.\r\n4. You are required to calculate and print the maximum value that can be created in the bag without overflowing it's capacity.\r\nNote1 -> Items can be added to the bag even partially. But you are not allowed to put same items again and again to the bag.","inputFormat":"A number n\r\nv1 v2 .. n number of elements\r\nw1 w2 .. n number of elements\r\nA number cap","outputFormat":"A decimal number representing the maximum value that can be created in the bag without overflowing it's capacity","constraints":"1 &lt;= n &lt;= 20\r\n0 &lt;= v1, v2, .. n elements &lt;= 50\r\n0 &lt; w1, w2, .. n elements &lt;= 10\r\n0 &lt; cap &lt;= 10","sampleCode":{"cpp":{"code":"#include<bits/stdc++.h>\r\nusing namespace std;\r\n\r\nint main(){\r\n \r\n}"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n\t\r\n\tpublic static void main(String[] args) {\r\n\t\tScanner scn = new Scanner(System.in);\r\n\t\tString str = scn.next();\r\n \r\n\t}\r\n\r\n}"},"python":{"code":"print()"}},"points":10,"difficulty":"easy","sampleInput":"10\r\n33 14 50 9 8 11 6 40 2 15 \r\n7 2 5 9 3 2 1 10 3 3 \r\n5","sampleOutput":"50.0","questionVideo":"","hints":[],"associated":[{"id":"79f25fd1-2a3b-420d-a05b-9fab8397566e","name":"Another name for Merkel-Hellman cryptosystem is","slug":"another-name-for-merkel-hellman-cryptosystem-is","type":4},{"id":"ba70b7b5-3b50-43af-97e9-05e904574b20","name":"What is the time complexity of Fractional Knapsack","slug":"what-is-the-time-complexity-of-fractional-knapsack","type":4},{"id":"bb5bb0c6-7cba-4186-809c-4564a3a2569d","name":"DP optimizes the solution by taking advantage of which of the following:","slug":"dp-optimizes-the-solution-by-taking-advantage-of-which-of-the-following","type":4}],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"52d62581-1313-45fb-aaf0-1d72a45f6a50","name":"Dynamic Programming And Greedy For Beginners","slug":"dynamic-programming-and-greedy-for-beginners","type":0},{"id":"0c2e4b9f-9e33-4dee-b160-8dd57aad6038","name":"Fractional Knapsack - Official","slug":"fractional-knapsack-official","type":1}],"next":{"id":"799a3962-2b02-4700-8a7c-0047d8858c55","name":"Fractional Knapsack - Official","type":3,"slug":"fractional-knapsack-official"},"prev":{"id":"0802c91b-a2f7-4ae7-a4ba-0a3199e2afb4","name":"Unbounded Knapsack","type":3,"slug":"unbounded-knapsack"}}}
plane

Editor


Loading...

Fractional Knapsack - Official

easy

1. You are given a number n, representing the count of items. 2. You are given n numbers, representing the values of n items. 3. You are given n numbers, representing the weights of n items. 3. You are given a number "cap", which is the capacity of a bag you've. 4. You are required to calculate and print the maximum value that can be created in the bag without overflowing it's capacity. Note1 -> Items can be added to the bag even partially. But you are not allowed to put same items again and again to the bag.

Constraints

1 <= n <= 20 0 <= v1, v2, .. n elements <= 50 0 < w1, w2, .. n elements <= 10 0 < cap <= 10

Format

Input

A number n v1 v2 .. n number of elements w1 w2 .. n number of elements A number cap

Output

A decimal number representing the maximum value that can be created in the bag without overflowing it's capacity

Example

Sample Input

10 33 14 50 9 8 11 6 40 2 15 7 2 5 9 3 2 1 10 3 3 5

Sample Output

50.0

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode