AmazonOA #19
Find Max Health Sum
Estimated EasyJudge-ready
Topics (AI-labelled)HashingIn-place Arrays
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.
Input
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
Output a single integer, the answer required by the problem.
Example 1
Input:
4 1
4 5 5 6
1 2 1 2
Output:
11
Example 2
Input:
1 1
8
1
Output:
8
Example 3
Input:
3 3
1 2 3
1 1 2
Output:
6
Example notes
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.
Editorial
Loading solution…