| Assiut University Training - Newcomers |
|---|
| Public |
| Spectator |
| Sheet #7 (Recursion) |
|---|
| Finished |
This contest uses time limits scaling policy (depending on a programming language). The system automatically adjusts time limits by the following multipliers for some languages. Despite scaling (adjustment), the time limit cannot be more than 30 seconds. Read the details by the link.
Given two numbers $$$N$$$ ,$$$X$$$ and an array $$$A$$$ of $$$N$$$ numbers. Determine if there is a way to put '+' or '-' signs between every two numbers in the array $$$A$$$ in order to make an expression that is equal to $$$X$$$.
Note: Solve this problem using recursion.
First line contains two numbers $$$N$$$ and $$$X$$$ $$$(1 \leq N \leq 20, -10^9 \leq X \leq 10^9)$$$.
Second line contains $$$N$$$ distinct numbers $$$A_1,A_2,....A_N$$$ $$$(1 \leq A_i \leq 10^5)$$$.
Print "YES" if you can put '+' or '-' signs between every two number to create an expression that is equal to $$$X$$$ otherwise, print "NO".
5 5 1 2 3 4 5
YES
5 2 1 2 3 4 5
NO
In the first example: 1 - 2 - 3 + 4 + 5 = 5
| Name |
|---|

