Array conversion
Tag(s):

## Algorithms, Dynamic Programming, Implementation, Medium, Two dimensional

Problem
Editorial
Analytics

You are given an array Arr containing N numbers and an integer K. You can implement the following operations on this array:

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

You cannot perform more than one operation per element of the array.

Write a program to determine whether it is possible to make the sum of all the elements in the array Arr equal to K.

Input format

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

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 ≤ Arr_i ≤ 100$

SAMPLE INPUT
2
3 2
1 1 1
4 5
1 2 3 4
SAMPLE OUTPUT
YES
YES
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.

Time Limit: 1,0 sec(s) for each input file.
Memory Limit: 256 MB
Source Limit: 1024 KB
Marking Scheme: Marks are awarded when all the testcases pass.
Allowed Languages: Bash, C, C++, C++14, Clojure, C#, D, Erlang, F#, Go, Groovy, Haskell, Java, Java 8, JavaScript(Rhino), JavaScript(Node.js), Julia, Kotlin, Lisp, Lisp (SBCL), Lua, Objective-C, OCaml, Octave, Pascal, Perl, PHP, Python, Python 3, R(RScript), Racket, Ruby, Rust, Scala, Swift, Swift-4.1, TypeScript, Visual Basic

## CODE EDITOR

Initializing Code Editor...

## This Problem was Asked in Challenge Name

KrypC Software Engineer Hiring Challenge

OTHER PROBLEMS OF THIS CHALLENGE
• Algorithms > Searching
• Math > Basic Math
Уведомления

?