[Question]
  [
Given an array of integers **`a`** which contains *n* integers, and a single integer **`x`**; remove the fewest amount of elements from **`a`** to make the sum of **`a`** equal to **`x`**. If no combinations of **`a`** can form **`x`**, return a falsy value.
As pointed out in a comment this is the maximum set with a sum of **x**, excuse my lesser math brain. I forgot a lot of terms since college.
---
**Examples (Truthy):**
`f([1,2,3,4,5,6,7,8,9,10], 10) = [1,2,3,4]`
`f([2,2,2,2,2,2,2,2,2], 10) = [2,2,2,2,2]`
`f([2,2,2,2,-2,-2,-2,-4,-2], -8) = [2,2,-2,-2,-2,-4,-2]`
`f([-2,-4,-2], -6) = [-4,-2] OR [-2,-4]`
`f([2,2,2,4,2,-2,-2,-2,-4,-2], 0) = [2,2,2,4,2,-2,-2,-2,-4,-2]` (Unchanged)
`f([], 0) = []` (Unchanged Zero-sum Case)
---
**Examples (Falsy, any consistent non-array value):**
**Impossible to Make Case:** `f([-2,4,6,-8], 3) = falsy (E.G. -1)`
**Zero Sum Case:** `f([], non-zero number) = falsy (E.G. -1)`
* *Note: any value like `[-1]` cannot be valid for falsy, as it is a potential truthy output.*
---
Rules:
* Input may be taken in array form, or as a list of arguments, the last or first being `x`.
* Output may be any delimited list of integers. E.G. `1\n2\n3\n` or `[1,2,3]`.
* Any value can be used as a falsy indicator, other than an array of integers.
* Your code must maximize the size of the end array, order does not matter.
	+ E.G. For `f([3,2,3],5)` both `[2,3]` and `[3,2]` are equally valid.
	+ E.G. For `f([1,1,2],2)` you can only return `[1,1]` as `[2]` is shorter.
* Both the sum of **`a`** and the value of **`x`** will be less than `2^32-1` and greater than `-2^32-1`.
* This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), lowest byte-count wins.
* If there are multiple subarrays of the same size that are valid, it is *not* acceptable to output all of them. You must choose a single one and output that one.
---
Let me know if this has been posted, I couldn't find it. 
Posts I found *like this*: [Related but closed](https://codegolf.stackexchange.com/questions/17981/sum-of-numbers-of-array), ...
  
[Answer]
# [Brachylog](https://github.com/JCumin/Brachylog), 8 bytes
```
h⊇.+~t?∧
```
[Try it online!](https://tio.run/##SypKTM6ozMlPN/r/P@NRV7uedl2J/aOO5f//R0fHG@nEm@jEG8XqxJvF/o8CAA "Brachylog – Try It Online")
Monthly Brachylog answer. Returns `false.` if it is not possible.
### Explanation
```
h⊇.           The output is a subset of the head of the input
  .+~t?       The sum of the elements of the output must equal the tail of the input
       ∧      (Avoid implicit unification between the output and the input)
```
[Answer]
# [Python 2](https://docs.python.org/2/), ~~108~~ 104 bytes
```
lambda a,n:[x for l in range(len(a)+1)for x in combinations(a,l)if sum(x)==n][-1]
from itertools import*
```
[Try it online!](https://tio.run/##jZDBaoQwFEX3fsWD2STtE4xjp7bgNxQKXVkXmRntBJIXiSnYr7eR0FHERUkI5N57csPrf/zNUj511eekpTlfJUik13qEzjrQoAicpK@W6ZaY5I@Cz/o46xdrzoqkV5YGJlFz1cHwbdjIq4qaOhVN0jlrQPnWeWv1AMr01vmHqXeKPHSsFpjjEQt8whM@Y4kvKLIGQWQcDhX82U2S3IkcNyvGDxDii7YDpPddhDNQaRlLdswVvgZOsSbe4e0dovuvtmwp2/GBfdDlNs/5ylevLdzmS0WYV1oG@7iJ53z6BQ "Python 2 – Try It Online")
-4 bytes, thanks to Jonathan Allan
---
# [Python 2](https://docs.python.org/2/), ~~108~~ 106 bytes
```
def f(a,n):
 q=[a]
 while q:
  x=q.pop(0);q+=[x[:i]+x[i+1:]for i in range(len(x))]
  if sum(x)==n:return x
```
[Try it online!](https://tio.run/##jZDBaoQwEIbvPsXAXhIci7p261ryDAuFnkIO0o01sBs1dWn26e2U0FXEQ0kIzPz/N3@Y/j62nc2n6awbaFiNllcRDELWKoLv1lw0DNQAL4anvutZyl@HWEgvK6NiL02cVarpHBgwFlxtPzW7aMs858SDaeDrdqVKCFs5Pd6cBT/1ztiRwmSGOe6xwGc84AuWeMQsVQhZymEn4E9WUfQgclydYN8B2efeBpA8bkEvUUkZQjbEBb4EDiEm1HB6g6D@Ky2dwzZ0YO/2o/1d3pkvps3c6ksF7SspSd6v7DmffgA "Python 2 – Try It Online")
-2 bytes, thanks to Janathan Frech
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 9 bytes
```
æʒOQ}0ªéθ
```
[Try it online!](https://tio.run/##yy9OTMpM/f//8LJTk/wDaw0OrTq88tyO//@jDXWMdIx1THRMdcx0zHUsdCx1DA1iuQwNDAA "05AB1E – Try It Online")
[Answer]
# [Japt](https://github.com/ETHproductions/japt) `-h`, 11 bytes
```
à f_x ¥VÃñl
```
[Try it online!](https://tio.run/##y0osKPn///AChbT4CoVDS8MONx/emPP/f7SRDgiaALEuHJkAyVgdBQMuLt0MAA "Japt – Try It Online")
[Answer]
# [Pyth](https://github.com/isaacg1/pyth), 8 bytes
* **8-byter** ([Try it!](https://pyth.herokuapp.com/?code=efqz%60sTy&input=%5B1%2C2%2C3%2C4%2C5%2C6%2C7%2C8%2C9%2C10%5D%0A10&test_suite=1&test_suite_input=%5B1%2C+2%2C+3%2C+4%2C+5%2C+6%2C+7%2C+8%2C+9%2C+10%5D%0A10%0A%0A%5B2%2C+2%2C+2%2C+2%2C+2%2C+2%2C+2%2C+2%2C+2%5D%0A10%0A%0A%5B2%2C+2%2C+2%2C+2%2C+-2%2C+-2%2C+-2%2C+-4%2C+-2%5D%0A-8%0A%0A%5B-2%2C+-4%2C+-2%5D%0A-6%0A%0A%5B2%2C+2%2C+2%2C+4%2C+2%2C+-2%2C+-2%2C+-2%2C+-4%2C+-2%5D%0A0%0A%0A%5B%5D%0A0%0A%0A%5B-2%2C+4%2C+6%2C+-8%5D%0A3%0A%0A%5B%5D%0A5%0A&debug=0&input_size=3)) – Outputs only one possible solution. For unsolvable inputs, it doesn't print anything to STDOUT, which is an empty string, which is technically speaking falsey in Pyth, but writes to STDERR. Thanks to [FryAmTheEggman](https://codegolf.stackexchange.com/users/31625/fryamtheeggman) for suggesting this (ignoring STDERR and focusing on the STDOUT output only), thus saving 1 byte.
```
efqz`sTy    
```
* **9-byter** ([Try it!](https://pyth.herokuapp.com/?code=%3E1fqz%60sTy&input=%5B1%2C2%2C3%2C4%2C5%2C6%2C7%2C8%2C9%2C10%5D%0A10&test_suite=1&test_suite_input=%5B1%2C+2%2C+3%2C+4%2C+5%2C+6%2C+7%2C+8%2C+9%2C+10%5D%0A10%0A%0A%5B2%2C+2%2C+2%2C+2%2C+2%2C+2%2C+2%2C+2%2C+2%5D%0A10%0A%0A%5B2%2C+2%2C+2%2C+2%2C+-2%2C+-2%2C+-2%2C+-4%2C+-2%5D%0A-8%0A%0A%5B-2%2C+-4%2C+-2%5D%0A-6%0A%0A%5B2%2C+2%2C+2%2C+4%2C+2%2C+-2%2C+-2%2C+-2%2C+-4%2C+-2%5D%0A0%0A%0A%5B%5D%0A0%0A%0A%5B-2%2C+4%2C+6%2C+-8%5D%0A3%0A%0A%5B%5D%0A5%0A&debug=0&input_size=3)) – Outputs only one possible solution, wrapped in a singleton list as [allowed by default](https://codegolf.meta.stackexchange.com/a/11884/59487) (e.g. `([1...10], 10) -> [[1,2,3,4]]; ([], 0) -> [[]]`). For unsolvable inputs, it returns `[]`, which is [falsey](https://pyth.herokuapp.com/?code=%21%21&input=%5B%5D&debug=0) in Pyth.
```
>1fqz`sTy
```
* **10-byter** ([Try it!](https://pyth.herokuapp.com/?code=e%2B0fqz%60sTy&input=%5B1%2C2%2C3%2C4%2C5%2C6%2C7%2C8%2C9%2C10%5D%0A10&test_suite=1&test_suite_input=%5B1%2C+2%2C+3%2C+4%2C+5%2C+6%2C+7%2C+8%2C+9%2C+10%5D%0A10%0A%0A%5B2%2C+2%2C+2%2C+2%2C+2%2C+2%2C+2%2C+2%2C+2%5D%0A10%0A%0A%5B2%2C+2%2C+2%2C+2%2C+-2%2C+-2%2C+-2%2C+-4%2C+-2%5D%0A-8%0A%0A%5B-2%2C+-4%2C+-2%5D%0A-6%0A%0A%5B2%2C+2%2C+2%2C+4%2C+2%2C+-2%2C+-2%2C+-2%2C+-4%2C+-2%5D%0A0%0A%0A%5B%5D%0A0%0A%0A%5B-2%2C+4%2C+6%2C+-8%5D%0A3%0A%0A%5B%5D%0A5%0A&debug=0&input_size=3)) – For a clearer output, without using the singleton-list rule and using `0` rather than `[]` as a falsy value.
```
e+0fqz`sTy
```
### Explanation
First, the code computes the powerset of the input list (all possible ordered sub-collections thereof). Then, it only keeps those collections whose sum is equal to the input number. It should be noted that the collections are generated from the shortest to the longest, so we focus on the last one. To obtain it:
* The **8-byter** simply uses the *end* built-in, which throws an error, but STDERR can be ignored as per our site rules, the output to STDOUT being an empty string, which is falsy.
* The **9-byter** takes the last element, but using the equivalent Python code `lst[-1:]` in place of `lst[-1]` to avoid errors from being thrown for unsolvable inputs.
* The **10-byter** prepends a **0** to the list of filtered sub-collections, then takes the end of that collection (last element). If the inputs aren't solvable, then **0** is naturally used instead.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 7 bytes
```
ŒPS⁼¥ƇṪ
```
[Try it online!](https://tio.run/##y0rNyan8///opIDgR417Di091v5w56r/h5cfnfRw54z//6ONdCBQF45MgGTsf10LAA "Jelly – Try It Online")
Output clarified over TIO.
[Answer]
# [Perl 6](https://github.com/nxadm/rakudo-pkg), ~~38~~ 37 bytes
```
{*.combinations.grep(*.sum==$_).tail}
```
[Try it online!](https://tio.run/##K0gtyjH7n1upoJamYPu/WksvOT83KTMvsSQzP69YL70otUBDS6@4NNfWViVeU68kMTOn9n9xYqVCmoZetGGsJpA0iNVUSMsv4tLQMNQx0jHWMdEx1THTMdex0LHUMTTQ1FEAEUBZIx00iCmlC0cmQBIor2sBlkcWMUPSYYJND8RIOEMXpMxMB2SSgjFMylDzPwA "Perl 6 – Try It Online")
Curried function.
[Answer]
# [Brachylog](https://github.com/JCumin/Brachylog), 4 bytes
```
⟨⊇+⟩
```
[Try it online!](https://tio.run/##SypKTM6ozMlPN/pf/ahjuVKahlK5fUa5ko4CkC4pV9JUsAWxqh@1bXjU1FwDVpKYU5yqp1T7cFdn7cOtE/4/mr/iUVe79qP5K///j46ONtQx0jHWMdEx1THTMdex0LHUMTSIBePoaCMdNIguEQ9HJkAyVifeAiSLxDdDqDbBoh5sGJSKBykxAxthDBE2MYqNBQA "Brachylog – Try It Online")
Just about equivalent to Fatalize's `h⊇.+~t?∧`, except a **lot** shorter, thanks to the *predicate composition* feature which according to [the edit history of the reference](https://github.com/JCumin/Brachylog/wiki/7)-Predicate-composition/_history) was a work in progress until January 8, postdating the answer by over two months. `⟨⊇+⟩` is a *sandwich*, expanding to `{[I,J]∧I⊇.+J∧}`, where the braces are in this case irrelevant as the sandwich is on its own line anyhow.
```
                The input
[I,J]           is a list of two elements I and J.
        .       The output,
         +J     which sums to J
           ∧    (which we don't unify with the output),
      I⊇        is a sublist of I
     ∧          (which we don't unify with [I,J]).
```
A far less dramatic transformation of Fatalize's answer, which uses the same predicates with the same variables but comes out a byte shorter from being organized differently:
# [Brachylog](https://github.com/JCumin/Brachylog), 7 bytes
```
h⊇.&t~+
```
[Try it online!](https://tio.run/##SypKTM6ozMlPN/pf/ahjuVKahlK5fUa5ko4CkC4pV9JUsAWxqh@1bXjU1FwDVpKYU5yqp1T7cFdn7cOtE/5nPOpq11MrqdP@/z86OtpQx0jHWMdEx1THTMdcx0LHUsfQIBaMo6ONdNAgukQ8HJkAyVideAuQLBLfDKHaBIt6sGFQKh6kxAxshDFE2MQoNhYA "Brachylog – Try It Online")
```
           The input
h          's first element
 ⊇         is a superlist of
  .        the output,
   &       and the input
    t      's last item
     ~+    is the sum of the elements of
           the output.
```
(Also, if anyone wants to see something odd, change any of the underscores in the test cases into hyphens.)
[Answer]
# [Pyth](https://github.com/isaacg1/pyth), 14 bytes
```
A.Q|>1fqsTHyG0
```
[Try it online!](https://tio.run/##K6gsyfj/31EvsMbOMK2wOMSj0t3g//9oQx0jHWMdEx1THbNYLkMDAA "Pyth – Try It Online")
[Answer]
# [Clean](https://github.com/Ourous/curated-clean-linux), 89 bytes
```
import StdEnv,Data.List,Data.Func
$n=find((==)n o sum)o sortBy(on(>)length)o subsequences
```
[Try it online!](https://tio.run/##PUyxCsIwFNz9ijd0SKF1EAeXOEgVhA5CR3F4pmkNJC/avAj9eWOkIHccdwd3ymqk5HwfrQaHhpJxTz8xdNwf6V01yLhuTeDFnSKpVUFyMNQLIWVJ4CFEV2bNq8MsPIl9aTWN/PiV8R70K2pSOqSOMR9LKKDewXVTLaj/3Ga9pY8aLI4h1ec2NTOhM2oJF4s8@Ml9AQ "Clean – Try It Online")
Defines the function `$ :: Int -> [Int] -> (Maybe [Int])` returning `Nothing` if there is no appropriate combination of elements, and `(Just [elements...])` otherwise.
[Answer]
# JavaScript (ES6), 108 bytes
Takes input as `(array)(n)`. Returns either an array or `false`.
```
a=>n=>a.reduce((a,x)=>[...a,...a.map(y=>1/r[(y=[...y]).push(x)]||eval(y.join`+`)-n?y:r=y)],[[]],r=!n&&[])&&r
```
[Try it online!](https://tio.run/##fZHfaoMwFMbv@xTZjSTsGGvrOjeIu9gDDAa7mQQaNPYPNpFklgp9d6dra0V0JyG5OOf35fvIXhyFTcyu@HGVTmWdsVqwSLFIUCPTMpEYCzgRFsWUUgHtQQ@iwBWLfM/Ezd02Kk5oUdotPhF@PsujyHFF93qn1o9r4qq36tWwinCIY87BsAflODEnjmPqRCurc0lzvcEZjn1YwBICeIIVPEMIL@DPOcH@nBDUlOeh2wifDdAFDFaPu6L31hTsdjtozkbBDVuFGzxoD1X63Kp7uatW5dJHH5/oMj3hJBjz0oa5xxgZQfhLJVuhNjIlQ90rP1Wtbp9H39Jo15YH9C6sJLORqEHzR27Y6C5Ho2Yit3LExfJ/F39Y/Qs "JavaScript (Node.js) – Try It Online")
[Answer]
This started out cool and small, but edge cases got me. Whatever happens, I'm proud of the work I put into this.
# [Python 3](https://docs.python.org/3/), ~~169 161~~ 154 bytes
```
from itertools import*
def f(a,x):
	if sum(a)==x:return a
	try:return[c for i in range(len(a))for c in combinations(a,i)if sum(c)==x][-1]
	except:return 0
```
[Try it online!](https://tio.run/##bZDdisMgEIWv41MM9EaXCeRvu9lCnqFQ2KuQC9dqKzQajIX06bOGptsQgiLMmfnOkeke/mpNPo7K2Ra0l85be@tBt511/oOcpQJFOQ7sQCKtoL@3lLOqGg5O@rszwEnk3WOuagHKOtCgDThuLpLepAnzbFLFpArb/mrDvbamD7aazZ5i8mzqOG1IJAchO/8KSMbOaeOBKlqnmGGOBX7iHr@wxG9MkwYhTRiDXQWvfkPIm8lwdWZgBwF4i1tI/H@L8AYuLuegje7SYIns56inAMcTPNsbicVWZrKI3BwB@mPEddr2mS09F@z6c0XYX1yGgZytkYyx8Q8 "Python 3 – Try It Online")
[Answer]
# [R](https://www.r-project.org/), ~~100~~ 80 bytes
```
function(a,x){i[sum(a|1):0,j[combn(a,i,,F),if(sum(j)==x)return(j)]]
F}
`[`=`for`
```
[Try it online!](https://tio.run/##fY3BCsIwEETv@QqPu7CFREuRYq/9iVJIDQ2k0ARiAwX122OiKGJBdlmYfcyMj3p3KqIOVi3GWRhoxavpLmGG4Saw5jR1ys3nTAxRi2Q0ZDph06zoxyV4m0Tfs/bOZCcbqZ2XUYOoBSfBkWlQsKefwQ0qPlumi1QcX/zrU/13PANtmEdvFPCtfjcmR0lVLqADxgc "R – Try It Online")
*20 bytes saved thanks to digEmAll*
Returns `FALSE` for impossible criteria.
[Answer]
# [Attache](https://github.com/ConorOBrien-Foxx/Attache), 28 bytes
```
${(y&`=@Sum\Radiations@x)@0}
```
[Try it online!](https://tio.run/##SywpSUzOSP2fpmBlq/BfpVqjUi3B1iG4NDcmKDElM7EkMz@v2KFC08Gg9r9fampKcbRKQUFyeixXQFFmXklIanGJc2JxanF0moODZ4qOQjSXAhBERxvqGOkY65jomOqY6ZjrWOhY6hgaxOoogAioCiMdNIhdWheOTIAkUI2uBVwNsqgZmk4TbHoRxqNwdEHKzXRAJisYIysxMYrlio39DwA "Attache – Try It Online")
## Alternatives
**34 bytes**: `f[x,y]:=({y=Sum@_}\Radiations@x)@0`
**30 bytes**: `First@${y&`=@Sum\Radiations@x}`
**29 bytes**: `{(_&`=@Sum\_2)@0}#/Radiations`
**29 bytes**: `${({y=Sum@_}\Radiations@x)@0}`
**29 bytes**: ``@&0@${y&`=@Sum\Radiations@x}`
**29 bytes**: `{_}@@${y&`=@Sum\Radiations@x}`
## Explanation
```
${(y&`=@Sum\Radiations@x)@0}
${                         }    function receiving two arguments, x and y
            Radiations@x        calculate the radiations of x
                                (simulates removing all possible subslices of x)
           \                    keep those radiations
        Sum                     ...whose sum...
     `=@                        ...equals...
   y&                           ...y
  (                     )@0     select the first one (always the longest)
```
[Answer]
# APL(NARS), 65 chars, 130 bytes
```
{m←⍺=+/¨v←1↓{0=⍴⍵:⊂⍬⋄s,(⊂1⌷⍵),¨s←∇1↓⍵}⍵⋄0=↑⍴b←m/v:⍬⋄b⊃⍨n⍳⌈/n←⍴¨b}
```
↓ is used because the first element of the set of sets would be one void set (here ⍬ Zilde),
that one want eliminate because it seems +/⍬ is zero...
For not find, or error it would return ⍬ or in print text:
```
  o←⎕fmt
  o ⍬
┌0─┐
│ 0│
└~─┘
```
test:
```
  z←{m←⍺=+/¨v←1↓{0=⍴⍵:⊂⍬⋄s,(⊂1⌷⍵),¨s←∇1↓⍵}⍵⋄0=↑⍴b←m/v:⍬⋄b⊃⍨n⍳⌈/n←⍴¨b}
  o 1 z ,1
┌1─┐
│ 1│
└~─┘
  o 2 z ,1
┌0─┐
│ 0│
└~─┘
  o 10 z 1 2 3 4 5 6 7 8 9 10
┌4───────┐
│ 1 2 3 4│
└~───────┘
  o 10 z 2,2,2,2,2,2,2,2,2
┌5─────────┐
│ 2 2 2 2 2│
└~─────────┘
  o ¯8 z 2,2,2,2,¯2,¯2,¯2,¯4,¯2
┌7──────────────────┐
│ 2 2 ¯2 ¯2 ¯2 ¯4 ¯2│
└~──────────────────┘
  o ¯6 z ¯2,¯4,¯2
┌2─────┐
│ ¯4 ¯2│
└~─────┘
  o 0 z 2,2,2,4,2,¯2,¯2,¯2,¯4,¯2
┌10───────────────────────┐
│ 2 2 2 4 2 ¯2 ¯2 ¯2 ¯4 ¯2│
└~────────────────────────┘
  o 10 z 1 2 3 4
┌4───────┐
│ 1 2 3 4│
└~───────┘
  o 10 z 1 2 3
┌0─┐
│ 0│
└~─┘
  o 0 z ⍬
┌0─┐
│ 0│
└~─┘
  o +/⍬  
0
~
```
[Answer]
# [Husk](https://github.com/barbuz/Husk), 8 bytes
```
▲fo=⁰ΣQ²
```
[Try it online!](https://tio.run/##ASQA2/9odXNr///ilrJmbz3igbDOo1HCsv///1stMiwtNCwtMl3/LTY "Husk – Try It Online")
Brachylog is **insane.**
[Answer]
# [Haskell](https://www.haskell.org/), 68 bytes
```
import Data.List
f x=find((==x).sum).sortOn(sum.(-1<$)).subsequences
```
[Try it online!](https://tio.run/##VYzNCoMwEITvPsUePETYiPGntdDceiz0AaSHVJM2VKM1EXz6pimFgswyLDMf8xD2Kfveez1M4@zgJJxIz9q6SMHKlTYdIZyvSWqXIVhALoaEPyWUHePkm9@sfC3StNL6QWgDHLoxAphmbRzEoIBl0DDMscASK9zhHms8IMuuG4rQOoEmx5/o/8rgWzLMbYMCmkCWYZrW26YKqH@3qhd362k7TR8 "Haskell – Try It Online")
Defines `f x a` to return `Just` a subset or `Nothing`.
The only trick here is that `sum.(-1<$)` is one byte shorter than `(0-).length`.
]