{"problem":{"name":"Synthetic Kadomatsu","description":{"content":"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, ","description_type":"Markdown"},"platform":"AtCoder","limit":{"time_limit":2000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"abc119_c"},"statements":[{"statement_type":"Markdown","content":"You have $N$ bamboos. The lengths (in centimeters) of these are $l_1, l_2, ..., l_N$, respectively.\nYour 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:\n\n*   Extension Magic: Consumes $1$ _MP_ (magic point). Choose one bamboo and increase its length by $1$.\n*   Shortening Magic: Consumes $1$ MP. Choose one bamboo of length at least $2$ and decrease its length by $1$.\n*   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.)\n\nAt least how much MP is needed to achieve the objective?\n\n## Constraints\n\n*   $3 \\leq N \\leq 8$\n*   $1 \\leq C < B < A \\leq 1000$\n*   $1 \\leq l_i \\leq 1000$\n*   All values in input are integers.\n\n## Input\n\nInput is given from Standard Input in the following format:\n\n$N$ $A$ $B$ $C$\n$l_1$\n$l_2$\n$:$\n$l_N$\n\n[samples]","is_translate":false,"language":"English"}],"meta":{"iden":"abc119_c","tags":[],"sample_group":[["5 100 90 80\n98\n40\n30\n21\n80","23\n\nWe are obtaining three bamboos of lengths $100, 90, 80$ from five bamboos $98, 40, 30, 21, 80$. We already have a bamboo of length $80$, and we can obtain bamboos of lengths $100, 90$ by using the magics as follows at the total cost of $23$ MP, which is optimal.\n\n1.  Use Extension Magic twice on the bamboo of length $98$ to obtain a bamboo of length $100$. (MP consumed: $2$)\n2.  Use Composition Magic on the bamboos of lengths $40, 30$ to obtain a bamboo of length $70$. (MP consumed: $10$)\n3.  Use Shortening Magic once on the bamboo of length $21$ to obtain a bamboo of length $20$. (MP consumed: $1$)\n4.  Use Composition Magic on the bamboo of length $70$ obtained in step 2 and the bamboo of length $20$ obtained in step 3 to obtain a bamboo of length $90$. (MP consumed: $10$)"],["8 100 90 80\n100\n100\n90\n90\n90\n80\n80\n80","0\n\nIf we already have all bamboos of the desired lengths, the amount of MP needed is $0$. As seen here, we do not necessarily need to use all the bamboos."],["8 1000 800 100\n300\n333\n400\n444\n500\n555\n600\n666","243"]],"created_at":"2026-03-03 11:01:14"}}