So hey, I've recently found this problem online and I tried hard to solve but couldn't found an efficient solution. The problem statement is:
Given and two integers $n$ and $k$ and an array $A$ containing $n$ pairs of integers of the form $(a, b)$ and $d$ defined as $d = |\sum_{x \in E} x[1] -x[0]| $ where is $E$ is a subset of $A$ containing exactly $k$ elements. Find the minimum value of $d$.
To illustrate the problem, consider $n = 3$, $k = 2$, $A = [(2, 1), (0, 2), (1, 2)]$.
The minimum value of $d$ is $0$. We can pick $E = [(1, 2), (2, 1)]$ containing $k = 2$ values of $A$ then $d = |(1 - 2) + (2 - 1)| = |0| = 0$.
I tried to solve this problem but only came up with the brute force solution which is terrible in terms of time complexity.
How can one solve this problem efficiently ?