Problems > Unlimited Supplies

Unlimited Supplies

Difficulty: 1600 3000 ms 128 MB

dp

Same knapsack, but every item is available in unlimited quantity. Maximize the value within capacity W.

Input: the first line has N and W; each of the next N lines has wi and vi.

Output: the maximum total value with repetition allowed.

Constraints:

  • 1 ≤ N ≤ 100
  • 1 ≤ W ≤ 1000
  • 1 ≤ wi ≤ 1000
  • 0 ≤ vi ≤ 104

Sample Tests

Input 1
2 8
3 30
5 60
Output 1
90
Input 2
1 3
2 5
Output 2
5

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.