HomeVolumesContestsSectionsForumsUsersPrintHelpAbout

Volumes > Kovrov IT > problem:


2010.H. 50282 - Coins

Guest
• Discussion of problem (1)

Volume problems

• 2009.I. 50278 - ATM
• 2010.A. 50287 - Providers
• 2010.B. 50281 - Primes
• 2010.C. 50255 - Bishops
• 2010.D. 50277 - Unusual Lottery
• 2010.E. 50664 - Polygons
• 2010.F. 50265 - Liars and Knights
• 2010.G. 50256 - Sequence
• 2010.H. 50282 - Coins
• 2010.I. 50257 - Galls village
• 2010.J. 50258 - String manipulations

Feedback

If you notice incorrect translations in Contester, please let author know.

Time limit 1500/2000/2000/2000 ms. Memory limit 65000/65000/65000/65000 Kb.
Автор: Игорь Андрианов, ВоГТУ.

Monetary system in Byteland contains of N kinds of coins of different denominations. During ATM software developing, there occured a problem to give out the requested sum with minimal quantity of coins. To solve it, the following greedy algorithm was introduced. At first, maximal quantity of coins of greatest denomination are taken. Then, for the remaining sum, maximal quantity of coins of lesser denomination (next one in descending order) are taken, and so forth.

For example, we have coins of denominations 1, 2 and 5. To pay sum of 13, two coins of 5 are taken, then one coin of 2 and then one coin of 1 are taken.

Your task is to define, if this algorithm works correctly in all cases for a given monetary system.

Input
The first line of the input contains N (1 ≤ N ≤ 1000). The second line contains N coin denominations in ascending order, separated by single spaces (1 ≤ Di ≤ 1000). The first denomination is always 1.

Output
If the introduced algorithm really gives out any sum with minimal quantity of coins, output 0. Otherwise output the minimal sum, that the algorithm will give out with non-minimal quantity of coins.

Input 1 Output 1
3
1 2 5
0
Input 2 Output 2
4
1 3 4 5
7

Для отправки решений необходимо выполнить вход.

www.contester.ru