Suppose I have a set of unique elements $A=\{a_1, a_2, ..., a_n\}$. Suppose I also have a metric function $f:A\times A \rightarrow R^+$. I want to choose $k$ elements from $A$ (i.e. $a_{i_1},a_{i_2}, ..., a_{i_k}$, $I=\{i_1,...,i_k\}$) such that it maximizes the sum:
$$S=\sum _ {i,.j\in I, i\neq j}^{}{f(a_i,a_j)}$$
Is there any known algorithm to do something like this? I know the Hungarian Algorithm can be used to solve the case of $k=n$. Can it be adapted for $k