Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

. . . ,, . ,, . , mr 11// T1118 15 a quote from the 1986 m0v1e, True Stor1es , and it s 10

image text in transcribed
. . . ,, . ,, . , \\\\\\\\\\\\mr \\\\\\\\11// T1118 15 a quote from the 1986 m0v1e, True Stor1es , and it s 10 hotdogs 8 buns true; well, almost true. You could buy four packs of 10 hotdogs and five packs of 8 buns. That would give you exactly 40 of each. However, you can make things even with fewer packs if you buy two packs of 10 hotdogs, along with a pack of 8 buns and another pack of 12 buns. That would give you 20 of each, using only 4 total packs. For this problem, you'll determine the fewest packs you need to buy to make hotdogs and buns come out even, given a selection of different bun and hotdog packs available for purchase. Input The first input line starts with an integer, H, the number of hotdog packs available. This is followed by H integers, hl . . . 111;, the number of hotdogs in each pack. The second input line starts with an integer, B, giving the number of bun packs available. This is followed by B integers, b1 . . . by, indicating the number of buns in each pack. The values H and B are between 0 and 100, inclusive, and the sizes of the packs are between 1 and 1 000, inclusive. Every available pack is listed individually. For example, if there were five eightbun packs available for purchase, the list of bun packs would contain five copies of the number eight. Output If it's not possible to purchase an equal number of one or more hotdogs and buns, just output \"impossible\". Otherwise, output the smallest number of total packs you can buy (counting both hotdog and bun packs) to get exactly the same number of hotdogs and buns. Imple 1 Input Output 4 18 18 18 18 4 19 8 8 8 12 12 12 8 8 12 12 Imple 2 Input Output 4 7 7 14 7 impossible 3 11 22 11

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Mobile Communications

Authors: Jochen Schiller

2nd edition

978-0321123817, 321123816, 978-8131724262

More Books

Students also viewed these Programming questions