#P6538. Maximum Value Bagging

    ID: 19751 Type: Default 1000ms 256MiB

Maximum Value Bagging

Maximum Value Bagging

You are given \(N\) items, each with a mass \(M_i\) and a value \(V_i\). Mirko has \(K\) bags, each with a capacity \(C_i\). Each bag can hold at most one item and an item can be placed in a bag only if its mass does not exceed the bag's capacity. Your task is to maximize the total value of the items that can be carried.

Mathematical formulation:

Find a subset of items and assign each chosen item to a distinct bag such that for each bag with capacity \(C_i\) and its assigned item with mass \(M_j\), it holds that \(M_j \leq C_i\). The objective is to maximize \(\sum V_j\) over all chosen items.

inputFormat

The first line contains two integers \(N\) and \(K\), representing the number of items and the number of bags respectively.

The next \(N\) lines each contain two integers \(M_i\) and \(V_i\) representing the mass and value of the \(i\)-th item.

The last line contains \(K\) integers, where the \(i\)-th integer is \(C_i\), the capacity of the \(i\)-th bag.

outputFormat

Output a single integer representing the maximum total value of items that can be carried.

sample

2 1
5 10
3 5
4
5