#K48552. Maximizing Trade Value

    ID: 28445 Type: Default 1000ms 256MiB

Maximizing Trade Value

Maximizing Trade Value

You are given a collection of items, each with a serial number and an associated trade value. Your task is to select a subset of these items such that the sum of their trade values is as large as possible without exceeding a given budget.

This problem can be modeled as a knapsack problem where both the weight and the value of each item are equal to its trade value. Formally, given a budget \(B\) and \(n\) items with trade values \(v_i\), you need to determine the maximum sum \(S = \sum_{i \in I} v_i\) such that \(S \le B\), where \(I\) is a subset of item indices.

inputFormat

The first line contains two integers (n) and (B), representing the number of items and the budget, respectively. Each of the following (n) lines contains two integers: the serial number of the item (which can be ignored) and its trade value.

outputFormat

Print a single integer representing the maximum total trade value achievable without exceeding the budget.## sample

5 10
1 5
2 3
3 9
4 8
5 2
10