Loading...
Loading...
Loading...
A shop has N coins, each with a value, and each coin can be used at most once. A customer must pay exactly T. Print YES if some of the coins add up to exactly T, otherwise NO.
Example 1
Input
6 9 3 34 4 12 5 2
Output
YES
4 + 5 = 9.
Example 2
Input
6 30 3 34 4 12 5 2
Output
NO
No group of coins makes 30.
Try the problem first. Open one hint at a time.
Keep a list of yes or no for each total from 0 to T. Total 0 is always possible.
For each coin, update the list from the largest total down to the coin value.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor