Array conversion
Practice
4.2 (10 votes)
Algorithms
Dynamic programming
Grammar Verified
Implementation
Medium
Two dimensional
Problem
62% Success 2721 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

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\)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
14 votes
Tags:
ApprovedCombinatoricsDynamic ProgrammingMathMediumOpenTwo dimensional
Points:30
18 votes
Tags:
ApprovedDynamic ProgrammingMathMediumNumber TheoryOpen
Points:30
7 votes
Tags:
AlgorithmsApprovedDynamic ProgrammingGreedy AlgorithmsMediumOpenSortingTwo dimensional