Problem: You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively.  Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number:    * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1.   * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1.   * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.)  At least how much MP is needed to achieve the objective?

Submission attempts (in order):
# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']

# 1 2	| x,y = map(int,input().split())   |	x=1,y=2




# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())



from collections import defaultdict, Counter
import math
from bisect import bisect_left, bisect_right
import numpy as np

li = list(map(int,input().split()))
N, A, B, C = li[0], li[1], li[2], li[3]
l = sorted([ int(input()) for i in range(N) ])
an_l = sorted([A, B, C])

ans = 0
for l_n_ind, l_n in enumerate(an_l):
    score = 10
    l_i_ind = None
    for ind, l_i in enumerate(l):
        tmp_score = abs(l_n-l_i)
        if tmp_score < score:
            score = tmp_score
            l_i_ind = ind
    if l_i_ind is not None:
        ans += score
        l.pop(l_i_ind)
        an_l.pop(l_n_ind)

# an_sum = sum(an_l)


for l_n_ind, l_n in enumerate(an_l):
    score = 99999
    l_i_inds = []
    for i in range(1 << len(l)):
        output = []
        output_ind = []
        l_i_ind = None
        for j in range(len(l)):
            if ((i >> j) & 1) == 1:
                output.append(l[j])
                output_ind.append(j)
        if len(output) == 0:
            continue
        tmp_score = abs(sum(output)-l_n)
        if tmp_score < score:
            score = tmp_score
            l_i_inds = output_ind

    ans += (score + (len(l_i_inds)-1)*10)
    print("l: {}".format(l_n))
    print("ls: ")
    for k in l_i_inds:
        print(l[k])
    for tt in l_i_inds[::-1]:
        l.pop(tt)

# print(an_l)
# print(l)
print(ans)



# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']

# 1 2	| x,y = map(int,input().split())   |	x=1,y=2




# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())


import math
import numpy as np
import copy
from collections import defaultdict, Counter
from itertools import product
from bisect import bisect_left, bisect_right
def inpl(): return list(map(int, input().split()))

li = list(map(int, input().split()))
N, A, B, C = li[0], li[1], li[2], li[3]
l = sorted([ int(input()) for i in range(N) ])

INF = 1e9

def dfs(ind, a, b, c):
    if ind == N:
        if min(a, b, c) > 0:
            return abs(a-A) + abs(b-B) + abs(c-C) - 30
        else:
            return INF
    ret0 = dfs(ind+1, a, b, c)
    ret1 = dfs(ind+1, a + l[ind], b, c) + 10
    ret2 = dfs(ind+1, a, b + l[ind], c) + 10
    ret3 = dfs(ind+1, a, b, c + l[ind]) + 10
    return min(ret0, ret1, ret2, ret3)

print(dfs(0, 0, 0, 0))

Verdicts: Wrong Answer

Accepted