using
System;
using
System.Collections.Generic;
public
class
GFG {
public
class
Pair {
public
int
first, second;
public
Pair(
int
first,
int
second)
{
this
.first = first;
this
.second = second;
}
}
static
int
MaxSumSubset(
int
[] values,
int
[] labels,
int
n,
int
limit)
{
int
res = 0;
HashSet<Pair> s =
new
HashSet<Pair>();
Dictionary<
int
,
int
> map
=
new
Dictionary<
int
,
int
>();
if
(n == 0) {
return
0;
}
for
(
int
i = 0; i < n; i++) {
s.Add(
new
Pair(values[i], labels[i]));
}
foreach
(Pair i
in
s)
{
if
(!map.ContainsKey(i.second)) {
map.Add(i.second, 0);
}
if
(map[i.second] < limit) {
map[i.second] = map[i.second] + 1;
res += i.first;
n--;
}
}
return
res;
}
static
public
void
Main()
{
int
[] values = { 5, 3, 7, 1, 2 };
int
[] labels = { 5, 7, 7, 7, 6 };
int
n = values.Length;
int
limit = 2;
Console.WriteLine(
MaxSumSubset(values, labels, n, limit));
}
}