AmazonOA #19
Find Max Health Sum
估计简单可在线判题
Choose at most m server types; once a type is chosen, every server of that type is selected. Find the maximum total health of the selected servers.
输入格式
The first line contains n m (1≤m≤n≤100000), the second line n health values (1..10⁹), and the third line n type IDs (1..n).
输出格式
Output a single integer, the answer required by the problem.
样例 1
输入:
4 1
4 5 5 6
1 2 1 2
输出:
11
样例 2
输入:
1 1
8
1
输出:
8
样例 3
输入:
3 3
1 2 3
1 1 2
输出:
6
样例说明
Example 1: type 1 has total health 4+5=9 and type 2 has 5+6=11; when only one type can be chosen, take type 2. Example 2: the only server has health 8. Example 3: there are only two types and up to 3 may be chosen, so choose both, for a total of 1+2+3=6.