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

C++ (gcc), 280 \$\cdots\$ 277 228 bytes

#import<bits/stdc++.h>
#define S(v)std::sort(v.begin(),v.end());
using V=std::vector<int>;V f(V&v){std::vector<V>w;S(v)for(int a:v)for(int b:v)for(int c:v)if(a+b+c==v.back()){V x={a,b,c};S(x)w.push_back(x);}S(w)return w.back();}

Try it online!

Uses Jonathan Allan's idea from his Jelly answer

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

Noodle9
  • 20.3k
  • 3
  • 21
  • 46