1+ #!usr/bin/env python3
2+ from collections import defaultdict , deque , Counter , OrderedDict
3+ from bisect import bisect_left , bisect_right
4+ from functools import reduce , lru_cache
5+ from heapq import heappush , heappop , heapify
6+
7+ import itertools
8+ import math , fractions
9+ import sys , copy
10+
11+ def L (): return sys .stdin .readline ().split ()
12+ def I (): return int (sys .stdin .readline ().rstrip ())
13+ def SL (): return list (sys .stdin .readline ().rstrip ())
14+ def LI (): return [int (x ) for x in sys .stdin .readline ().split ()]
15+ def LI1 (): return [int (x ) - 1 for x in sys .stdin .readline ().split ()]
16+ def LS (): return [list (x ) for x in sys .stdin .readline ().split ()]
17+ def R (n ): return [sys .stdin .readline ().strip () for _ in range (n )]
18+ def LR (n ): return [L () for _ in range (n )]
19+ def IR (n ): return [I () for _ in range (n )]
20+ def LIR (n ): return [LI () for _ in range (n )]
21+ def LIR1 (n ): return [LI1 () for _ in range (n )]
22+ def SLR (n ): return [SL () for _ in range (n )]
23+ def LSR (n ): return [LS () for _ in range (n )]
24+
25+ def perm (n , r ): return math .factorial (n ) // math .factorial (r )
26+ def comb (n , r ): return math .factorial (n ) // (math .factorial (r ) * math .factorial (n - r ))
27+
28+ def make_list (n , * args , default = 0 ): return [make_list (* args , default = default ) for _ in range (n )] if args else [default for _ in range (n )]
29+
30+ dire = [[1 , 0 ], [0 , 1 ], [- 1 , 0 ], [0 , - 1 ]]
31+ dire8 = [[1 , 0 ], [1 , 1 ], [0 , 1 ], [- 1 , 1 ], [- 1 , 0 ], [- 1 , - 1 ], [0 , - 1 ], [1 , - 1 ]]
32+ alphabets = "abcdefghijklmnopqrstuvwxyz"
33+ ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
34+ MOD = 1000000007
35+ INF = float ("inf" )
36+
37+ sys .setrecursionlimit (1000000 )
38+
39+ def main ():
40+ N , A , B , C = LI ()
41+ L = IR (N )
42+ ans = INF
43+
44+ for pattern in itertools .product ([0 , 1 , 2 , 3 ], repeat = N ):
45+ x , y , z , rest = [], [], [], []
46+ for i in range (N ):
47+ if pattern [i ] == 0 :
48+ x .append (L [i ])
49+ elif pattern [i ] == 1 :
50+ y .append (L [i ])
51+ elif pattern [i ] == 2 :
52+ z .append (L [i ])
53+ else :
54+ rest .append (L [i ])
55+
56+ cost = max ((len (x )- 1 )* 10 ,0 ) + max ((len (y )- 1 )* 10 , 0 ) + max ((len (z )- 1 )* 10 , 0 )
57+
58+ al , bl , cl = sum (x ) if x else INF , sum (y ) if y else INF , sum (z ) if z else INF
59+ block = [al , bl , cl ] + rest
60+
61+ for comb in itertools .combinations (block , r = 3 ):
62+ c , b , a = sorted (comb )
63+ ans = min (ans , cost + abs (A - a ) + abs (B - b ) + abs (C - c ))
64+
65+ print (ans )
66+
67+
68+
69+
70+
71+ if __name__ == '__main__' :
72+ main ()
0 commit comments