I've spent some time on the following problem, which is quite generic:
You are given $$$2n$$$ pairs of integers $$$(x_i, y_i)$$$, where $$$1 \leq x_i, y_i \leq M$$$. Your goal is to choose exactly $$$n$$$ of them, such that their pointwise sum $$$(X, Y)$$$ (that is, you sum each coordinate on its own), minimizes the cost function $$$f(X, Y)$$$. What is the best time complexity you can achieve, given some properties about the function $$$f$$$?
Since the time complexity can depend on both $$$n$$$ and $$$M$$$, the order in which the best complexity is determined is:
Polynomial in $$$n$$$ and in $$$\log M$$$.
Polynomial in $$$n$$$ and in $$$M$$$.
$$$O(\binom{2n}{n})$$$ (applicable to all of them).
Try to solve each of the following variations, with varying difficulties. This post is purposed for all levels :).
I'm interested to know if you have any other variations with interesting insights that I can add to here, as I find this topic quite interesting to research.
$$$f(X,Y) = X + Y$$$
$$$f$$$ can be any function
$$$text$$$
$$$text$$$
$$$text$$$