Skip to main content
15 of 15
deleted 14 characters in body
Noodle9
  • 20.3k
  • 3
  • 21
  • 46

C++ (gcc), 280 \$\cdots\$ 211 210 bytes

#import<regex>
#define S(v)std::sort(&v[0],&*end(v))
using V=std::vector<int>;int f(V&v){V r=v,x;S(v);int m=v.back(),n=m,t;for(int a:r)for(int b:r)for(int c:r)x={a,b,c},S(x),t=x[2]-x[0],v=t<m&a+b+c==n?m=t,x:v;}

Try it online!

Saved 3 4 bytes thanks to ceilingcat!!!

Inputs a vector of integers.
Replaces the input vector with the cartesian product of 3 elements of the input vector that add up to the maximum of the input vector and that have the minimum difference between the smallest and the largest element from all of the cartesian products.

Noodle9
  • 20.3k
  • 3
  • 21
  • 46