Skip to main content
11 of 15
edited body
Noodle9
  • 20.3k
  • 3
  • 21
  • 46

C++ (clang), 280 \$\cdots\$ 220 217 bytes

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

Try it online!

Saved 3 bytes thanks to ceilingcat!!!

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

Noodle9
  • 20.3k
  • 3
  • 21
  • 46