#P4571. [JSOI2009] 瓶子和燃料
[JSOI2009] 瓶子和燃料
Description
jyy has always wanted to return to Earth as soon as possible, but unfortunately his spaceship does not have enough fuel. One day he went to ask the Martians for fuel again. This time the Martians agreed, asking jyy to trade with the bottles on his spaceship. There are bottles on jyy's spaceship (), and after negotiation, the Martians only want of them.
After jyy gives bottles to the Martians, they use them to fill some fuel for jyy. None of the bottles have graduation marks; only the capacity is labeled at the mouth. The capacity of the -th bottle is ( is an integer and satisfies ). The Martians are stingy and will not fill all bottles to the brim. After they take the bottles, they will fiddle around in the fuel depot and produce a tiny amount of fuel just to get by. jyy certainly knows this trick, so he learned in advance exactly what the Martians do.
In the fuel depot, the Martians only perform the following types of operations:
- Fill some bottle completely with fuel;
- Pour all the fuel in some bottle back into the depot;
- Pour fuel from bottle into bottle until bottle is full or bottle is empty. Loss during the pouring process can be ignored.
The fuel they hand over is, of course, the smallest positive volume obtainable by these operations. jyy knows that for different choices of bottles, the Martians might be forced to give different volumes of fuel. jyy wants to find the optimal set of bottles so that the Martians are forced to give as much fuel as possible.
Input Format
The first line contains two integers . The next lines each contain one integer; the integer on the -th line is .
Output Format
Output a single integer on one line, representing the maximum amount of fuel the Martians will be forced to give.
3 2
3
4
4
4
Hint
Choose the 2nd and 3rd bottles; the Martians will be forced to give a volume of 4.
Translated by ChatGPT 5
京公网安备 11011102002149号