{"trustable":true,"prependHtml":"\u003cstyle type\u003d\"text/css\"\u003e\n div.illustration {\n float: right;\n padding-left: 20px;\n }\n div.illustration .illustration {\n width: 100%;\n border-radius: 4px;\n }\n pre {\n display: block;\n margin: 0 0 10px;\n font-size: 13px;\n line-height: 1.42857143;\n color: #333;\n word-break: break-all;\n word-wrap: break-word;\n }\n\u003c/style\u003e\n\u003cscript\u003e\n window.katexOptions \u003d {\n delimiters: [\n {left: \u0027\\\\[\u0027, right: \u0027\\\\]\u0027, display: true}\n ]\n };\n\u003c/script\u003e\n","sections":[{"title":"","value":{"format":"HTML","content":"\n \u003cdiv style\u003d\"width:35.00%\" class\u003d\"illustration\"\u003e\n \u003cimg src\u003d\"CDN_BASE_URL/4075b9349f981d2e8b3294aca0362be0?v\u003d1715181646\" alt\u003d\"/problems/ninepacks/file/statement/en/img-0001.png\" class\u003d\"illustration\"\u003e\n\n \n \u003c/div\u003e\n\n \u003cblockquote class\u003d\"quote\"\u003e\n “It’s like how hot dogs come in packs of ten, and buns come\n in packs of eight or twelve — you have to buy nine packs to\n make it come out even.”\n \u003c/blockquote\u003e\n\n \u003cp\u003eThis is a quote from the 1986 movie, “True Stories”, and\n it’s true; well, almost true. You could buy four packs of\n \u003cspan class\u003d\"tex2jax_process\"\u003e$10$\u003c/span\u003e hotdogs and five\n packs of \u003cspan class\u003d\"tex2jax_process\"\u003e$8$\u003c/span\u003e buns. That\n would give you exactly \u003cspan class\u003d\"tex2jax_process\"\u003e$40$\u003c/span\u003e of each. However, you can make\n things even with fewer packs if you buy two packs of\n \u003cspan class\u003d\"tex2jax_process\"\u003e$10$\u003c/span\u003e hotdogs, along with a\n pack of \u003cspan class\u003d\"tex2jax_process\"\u003e$8$\u003c/span\u003e buns and\n another pack of \u003cspan class\u003d\"tex2jax_process\"\u003e$12$\u003c/span\u003e buns.\n That would give you \u003cspan class\u003d\"tex2jax_process\"\u003e$20$\u003c/span\u003e\n of each, using only \u003cspan class\u003d\"tex2jax_process\"\u003e$4$\u003c/span\u003e\n total packs.\u003c/p\u003e\n\n \u003cp\u003eFor this problem, you’ll determine the fewest packs you need\n to buy to make hotdogs and buns come out even, given a\n selection of different bun and hotdog packs available for\n purchase.\u003c/p\u003e\n\n \u003ch2\u003eInput\u003c/h2\u003e\n\n \u003cp\u003eThe first input line starts with an integer, \u003cspan class\u003d\"tex2jax_process\"\u003e$H$\u003c/span\u003e, the number of hotdog packs\n available. This is followed by \u003cspan class\u003d\"tex2jax_process\"\u003e$H$\u003c/span\u003e integers, \u003cspan class\u003d\"tex2jax_process\"\u003e$h_1 \\ldots h_ H$\u003c/span\u003e, the number of\n hotdogs in each pack. The second input line starts with an\n integer, \u003cspan class\u003d\"tex2jax_process\"\u003e$B$\u003c/span\u003e, giving the\n number of bun packs available. This is followed by \u003cspan class\u003d\"tex2jax_process\"\u003e$B$\u003c/span\u003e integers, \u003cspan class\u003d\"tex2jax_process\"\u003e$b_1 \\ldots b_ B$\u003c/span\u003e, indicating the\n number of buns in each pack. The values \u003cspan class\u003d\"tex2jax_process\"\u003e$H$\u003c/span\u003e and \u003cspan class\u003d\"tex2jax_process\"\u003e$B$\u003c/span\u003e are between \u003cspan class\u003d\"tex2jax_process\"\u003e$0$\u003c/span\u003e and \u003cspan class\u003d\"tex2jax_process\"\u003e$100$\u003c/span\u003e, inclusive, and the sizes of the\n packs are between \u003cspan class\u003d\"tex2jax_process\"\u003e$1$\u003c/span\u003e and\n \u003cspan class\u003d\"tex2jax_process\"\u003e$1\\, 000$\u003c/span\u003e, inclusive.\n Every available pack is listed individually. For example, if\n there were five eight-bun packs available for purchase, the\n list of bun packs would contain five copies of the number\n eight.\u003c/p\u003e\n\n \u003ch2\u003eOutput\u003c/h2\u003e\n\n \u003cp\u003eIf it’s not possible to purchase an equal number of one or\n more hotdogs and buns, just output “\u003cspan style\u003d\"width:\" class\u003d\"mbox\"\u003eimpossible\u003c/span\u003e”. Otherwise, output the smallest\n number of total packs you can buy (counting both hotdog and bun\n packs) to get exactly the same number of hotdogs and buns.\u003c/p\u003e\n\n \u003ch2\u003eSample 1\u003c/h2\u003e\u003cbody\u003e\u003ctable class\u003d\"vjudge_sample\"\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e4 10 10 10 10\n10 8 8 8 12 12 12 8 8 12 12\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e4\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\u003c/body\u003e\n\n \u003ch2\u003eSample 2\u003c/h2\u003e\u003cbody\u003e\u003ctable class\u003d\"vjudge_sample\"\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e4 7 7 14 7\n3 11 22 11\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003eimpossible\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\u003c/body\u003e\n "}}]}