|시간 제한||메모리 제한||제출||정답||맞힌 사람||정답 비율|
|1 초||512 MB||58||13||11||20.755%|
You are the owner of IKEA, and you need to order a large number of bolts B. There is a single bolt manufacturer, but there are multiple companies reselling these bolts in packs (e.g. boxes, pallets). These companies form a directed chain, where each company buys packs from the previous company and combines these into new packs (with, of course, the logo of the company displayed brilliantly).
At first glance, it might seem that these intermediate companies offer no advantage, as they just repack the packs of the previous company into larger packs. However, every company has their own target audience, so they want to sell packs with a specific amount of bolts. Because every company only uses the packs of the previous company, it might not be possible to create a pack that has the exact number of bolts specified. Instead, if a company wants to create a pack which is guaranteed to contain X bolts, it will bundle various packs from the previous company where the displayed amount of bolts on these packs sums to no less than X. If there are multiple such combinations it will pick any from those whose displayed sum is minimal. For a better understanding, see the example below. Note that individual companies have no knowledge of the supply chain other than the pack sizes the previous company offers them.
You realise you can take advantage of this: when a company specifies that a pack has a certain number of bolts, it might in practice contain more! Therefore you start a quest of figuring out which pack has the lowest advertised amount, while still containing at least the number of bolts you need. Thanks to your business relations, you can freely choose the company to buy a pack from, including the manufacturer.
impossibleif this cannot be achieved.
310 3 2 40 65 2 100 150 2 300 320
Suppose that we would like to buy B = 310 bolts, and that there are three companies. The manufacturer (company one) sells packs of 40 and 65 bolts. Company two sells packs of 100 and 150 bolts. It cannot get these exact amounts from company one, and instead composes them as 100 ≤ 40 + 65 and 150 ≤ 40 + 40 + 40 + 40.
Next comes company three, offering packs of 300 and 320 bolts. It can assemble its 300-pack using three 100-packs (which we know will actually contain 105 + 105 + 105 = 315 bolts) or using two 150-packs (which we know will actually contain 160 + 160 = 320 bolts). However, for company three either combination is fine, so you do not know how many bolts a pack will actually contain. In this case you assume the worst, i.e. that this pack contains 315 bolts.
For its second pack of 320 bolts, company three will use 100 + 100 + 150 ≥ 320 (which we know really contains 105 + 105 + 160 = 370 bolts). There are other combinations adding up to more than 320, but none achieve the minimum of 350, so we know company three will pick that combination.
Note in particular, that company three does not know that the 150-packs of company two actually contain 160 bolts (otherwise it could compose its 320-pack out of two of these). It only knows the amounts advertised by company two.
The packet of size 300 sold by company three is the smallest advertised packet that contains at least B = 310 bolts, so this is the packet we should buy.
371 3 2 40 65 2 100 150 2 300 320
90 2 2 20 35 2 88 200
91 2 2 20 35 2 88 200