ГлавнаяСборникиТурнирыРазделыФорумыУчастникиПечатьПомощьО системе

Сборники > Kovrov IT > задача:


2010.H. 50282 - Coins

Гость
• Обсуждение задачи (1)

Задачи сборника

• 2009.H. 50268 - Triangles
• 2009.I. 50278 - ATM
• 2010.A. 50287 - Providers
• 2010.B. 50281 - Primes
• 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
• 2007.C. 50640 - Cubes
• 2007.D. 50271 - Factorial
• 2007.K. 50276 - Nice Floor
• 2007.A. 50671 - Phalanx
• 2007.B. 50270 - Bitsorting
• 2007.E. 50663 - Lights

Обратная связь

Если у вас есть предложения или пожелания по работе Contester, посетите форум сайта www.contester.ru.

Лимит времени 1500/2000/2000/2000 мс. Лимит памяти 65000/65000/65000/65000 Кб.
Автор: Игорь Андрианов, ВоГТУ.

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