#C6974. Maximum Total Value by Selecting Items

    ID: 50793 Type: Default 1000ms 256MiB

Maximum Total Value by Selecting Items

Maximum Total Value by Selecting Items

You are given a collection of n items. Each item has a type and a value. There are k different types. Your task is to choose at most one item from each type so that the total sum of the values is maximized.

Formally, let the items be numbered from 1 through n. For each item i, you are given its type t_i and value v_i. You can select at most one item for every type. Find the maximum total value achievable.

The mathematical formulation is as follows:

\[ \text{Maximize } \sum_{j=1}^{k} x_j \quad \text{subject to } x_j = \max\{ v_i : t_i = j \} \text{ for each type } j \text{ if any exist, otherwise } 0. \]

Input/Output: The input is read from standard input and the output is printed to standard output.

inputFormat

The first line contains two integers n and k separated by space, where n is the number of items and k is the number of types.

The second line contains n integers representing the types of the items.

The third line contains n integers representing the values of the items.

If n = 0, the next two lines will be empty.

outputFormat

Output a single integer which is the maximum total value by selecting at most one item from each type.

## sample
5 3
1 2 2 3 3
4 5 6 3 7
17

</p>