Knapsacks
Practice
3.8 (34 votes)
Algorithms
Dynamic programming
Problem
91% Success 8149 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

You are given \(n\) objects, a knapsack of capacity \(c\), array \(v\), and array \(w\). The \(i^{th}\) object has value v[i] and weight w[i].

Determine the maximum total value that you can get by selecting objects in such a manner that their sum of weights is not greater than the capacity \(c\).

Input format

  • First line: Two integers \(n\) and \(c\) denoting the number of objects and capacity of the knapsack (\(1 \le n \le 10^3\) and \(0 \le c \le 2×10^6\)
  • Second line: \(n\) integers \(v_1,\ v_2,\ ..., v_n\) (\(0 \le v_i \le 50\))
  • Third line: \(n\) integers \(w_1,\ w_2,\ ...,\ w_n\) (\(0 \le w_i \le 2×10^6\))

Output format

Print a single integer denoting the maximum value that you can get by selecting the objects.

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
41 votes
Tags:
AlgorithmsDynamic ProgrammingGreedy Algorithms
Points:30
61 votes
Tags:
Dynamic ProgrammingAlgorithmsIntroduction to Dynamic Programming 1
Points:30
65 votes
Tags:
Dynamic ProgrammingAlgorithmsIntroduction to Dynamic Programming 1