Submit | All submissions | Best solutions | Back to list |
NOCHANGE - No Change |
Though it might be hard to imagine, the inhabitants of a small country Additivia do not know of such thing as change, which probably has to do with them not knowing subtraction either. When they buy something, they always need to have the exact amount of addollars, their currency. The only other option, but not a really attractive one, is over-paying.
Professor Adem, one of the Additivian mathematicians came up with an algorithm for keeping a balanced portfolio. The idea is the following. Suppose you have more coins of value $v_1$ than coins of value $v_2$. In this case you should try to spend at least as many coins of value $v_1$ as those of value $v_2$ on any buy you make. Of course spending too many $v_1$ coins is not a good idea either, but to make the algorithm simpler professor Adem decided to ignore the problem. The algorithm became an instant hit and professor Adem is now designing a kind of "electronic portfolio" with built-in Adem's algorithm. All he needs now is a software for these machines, that will decide whether a given amount of addollars can be paid using a given set of coins according to the rules of Adem's algorithm. Needless to say, you are his chosen programmer for the task.
Problem
Write a program that reads the description of a set of coins and an amount of addollars to be paid, and determines whether you can pay that amount according to Professor Adem's rules.
Input
The input starts with the amount of addollars to be paid $x$, where $1 \le x \le 100,000$. The number of different coin values $k$ follows, where $1 \le k \le 5$. The values of the coins $v_1 \ldots v_k$ follow, where $1 \le v_i \le 10,000$.
Notice that the order among coin values is significant: you need to spend at least as many coins of value $v_1$ as coins of value $v_2$, at least as many coins of value $v_2$ as those of value $v_3$, and so on. You may assume that you have a sufficiently large number of coins of each value.
Output
Your program should output for each test case either a single word "YES", if the given amount can be paid according to the rules, or a single word "NO" otherwise.
Example
Input: 13 3 9 2 1 Output: NO
Added by: | overwise |
Date: | 2007-10-04 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ERL JS-RHINO NODEJS PERL6 VB.NET |
Resource: | ACM ICPC -- SWERC 2001 |
hide comments
|
||||||||
2016-01-28 13:04:02 minhthai
such a nice problem :) |
||||||||
2016-01-25 19:13:13
nice recursion with memo -> 0.00 |
||||||||
2015-11-19 14:31:55 abhilash tayade
my top down gives tle... :(...bottom up accepted |
||||||||
2015-08-04 08:53:44 Tej Bahadur Singh
not getting to problem uderstand |
||||||||
2015-05-27 11:42:59 bitwise
my optimized (x*k*k) soln giving AC in (0.0) sec AC in one go :) |
||||||||
2015-05-23 20:26:22 Shubham Jadhav
x*k solution passes, with 0.01 clocked.. |
||||||||
2015-03-22 07:22:24 Soumik Chatterjee
Last edit: 2015-03-27 17:12:20 |
||||||||
2015-01-29 06:52:18 TUSHAR SINGHAL
getting tle at test case 9 .. ??? |
||||||||
2015-01-24 14:41:42 .:frUstrAteD:.
41 5 5 1 5 7 3 YES 41 5 2 4 10 4 10 NO |
||||||||
2015-01-13 19:30:02 CoNtRaDiCtIoN
awesome problem !! loved it after solving !! |