This can be solved as a MIP (Mixed-Integer Programming) problem:
min |deviation|
subject to sum(i, value[i]*x[i]) = target + deviation
x[i] ∈ {0,1}
Some code to test this:
import cvxpy as cp
import random
#
# problem size
#
N = 40000
I = range(N)
#
# problem data
#
target = 100000
random.seed(12345)
p = [random.randrange(0,10000) for i in I]
#
# model
#
x = cp.Variable(N,boolean=True)
deviation = cp.Variable(1)
prob = cp.Problem(cp.Minimize(cp.abs(deviation)),[p@x==target+deviation])
#
# solve and reporting
#
prob.solve(solver=cp.CBC,verbose=True)
xsum = 0
for i in I:
if x[i].value > 0.5:
print(f"i:{i} value:{p[i]}")
xsum += p[i]
print(f"sum={xsum}")
Results:
-------------------------------------------------------------------------------
Summary
-------------------------------------------------------------------------------
(CVXPY) Dec 23 12:35:28 PM: Problem status: optimal
(CVXPY) Dec 23 12:35:28 PM: Optimal value: 1.438e-11
(CVXPY) Dec 23 12:35:28 PM: Compilation took 9.899e-02 seconds
(CVXPY) Dec 23 12:35:28 PM: Solver (including time spent in interface) took 1.156e+00 seconds
i:6 value:9273
i:9 value:6112
i:11 value:7093
i:13 value:9209
i:15 value:9063
i:3857 value:9209
i:9341 value:2035
i:12413 value:9209
i:15914 value:2035
i:15989 value:2126
i:16558 value:2035
i:16965 value:2035
i:24271 value:63
i:24290 value:7093
i:26791 value:624
i:30330 value:6752
i:32612 value:6752
i:34308 value:219
i:36798 value:9063
sum=100000
In this example, I used 40k integer values between 0 and 10k. I assume values are integers from the example data in the question. The MIP solver CBC needed about a second to find a combination that forms exactly 100k.