Special Array

5

1 votes
Algorithms, Dynamic Programming, 2D dynamic programming
Problem

An array A of N integers is said to special if we can obtain the total sum of the array as K by the implementation of the following operation:

  • Replace an element A[i] with A[i] + i
  • Replace an element A[i] with -A[i]
  • Replace an element A[i] with A[i] - i

Note: You can only perform one operation per element of the array.

If it is possible to make the sum of the array A equal to K i.e Special Array, print YES else NO.

Input format

  • First line: T (number of test cases)
  • First-line in each test case: Two space-separated integers N and K
  • The second line in each test case: N space-separated integers (denoting the array A)

Output format

For each test case, print YES or NO depending on the result.

Constraints

  • 1 ≤ T ≤ 50
  • 1 ≤ N ≤ 100
  • 1 ≤ K ≤ 10000
  • 0 ≤ A[i] ≤ 100
Sample Input
2
3 2
1 1 1
4 5
1 2 3 4
Sample Output
YES
YES
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

For testcase 2 if we change the given array {1,2,3,4} to {-1,4,6,-4}

By applying transformation 1 to element 1 and 4 making them 1->-1 and 4->-4
Transformation 2 to element 2 and 3 making them 2->2+2 and 3->3+3
then the sum of all the elements will be 5.

Editor Image

?