I have a function $f$ that takes $n \geq 1$ positive real-valued arguments $\mathbf{a} \in R^n_+$. This function is defined for all amounts of inputs (e.g. $f(1)$ and $f(3, \pi, 17)$ are both valid) and returns to me a score in the range of $[-\inf, 1]$. I want to find the smallest $n$ and the values of those $n$ arguments that maximizes $f$. How can I formulate (and hopefully solve) this optimization problem?
I'm thinking it should be something like:
$$ \begin{align} (\hat n, \hat{\mathbf a}) = \underset{n, \mathbf{a}}{\arg\max} \; & (-n, f(\mathbf{a})) \\ \text{s.t.} &\; n = |\mathbf{a}| \\ &\; a_i > 0 \; \forall i \end{align} $$
and maybe I can solve it using Markov Chain Monte Carlo? Could someone please help point me in the right direction?
Due to you have a restriction, maybe an approach using Lagrange's polynomials could help, but I don't have any idea of how to depict the process.