Skip to main content
1 of 2
l4m2
  • 28.5k
  • 2
  • 25
  • 104

JavaScript (Node.js), 95 bytes

a=>(N=g=([p,q,...x],n,...s)=>1/p?g(x,n+p,...s,p)+g([q,...x],n,...s):N>n|s<g||[N=n,S=s])(a,0)&&S

Try it online!

awful

l4m2
  • 28.5k
  • 2
  • 25
  • 104