Knapsack 4 - MarisaOJ: Marisa Online Judge

Knapsack 4

Time limit: 1000 ms
Memory limit: 256 MB
There are n items, ith item has the weight of wi and value of vi. You can choose an arbitrary number items as long as their weight doesn't exceed a given S. Find a way of choosing items so that their value is maximum possible. ### Input - First line contains 2 integers n and S. - Each line in the next n line contains 2 integers wi, vi. ### Output - The maximum possible value you can obtain. ### Constraints - 1≤n≤500. - 1≤S≤109. - 1≤wi≤109. - 1≤vi≤500. ### Example Input: 3514412100 Output: 104
Topic
Dynamic Programming
Rating 1400
Solution (1) Solution