Tug of War
InterviewTime limit1sMemory limit128 MB
Decide whether N student weights (4 to 30) split into two teams whose total strengths differ by at most X.
- Level
Medium5 of 10
- Topics
- Dynamic programming
- Solved
- No attempts yet
Problem
The computer science department of Pilseung University is preparing its autumn sports day. The last event is tug of war. To keep the department together and make the match fun, the students are split so that the two opposing teams are as evenly matched as possible. The strength of a team is the sum of the weights of the students on it.
Write a program that decides whether the students can be split into two teams whose strengths differ by at most . The two teams do not have to have the same number of students.
Input
Input arrives on standard input. The first line holds the number of test cases ().
Each test case takes three lines. The first line has the number of students (), the second line has an integer (), and the third line has the weights of the students, separated by spaces. Every weight is an integer between and .
Output
Write the answers to standard output. For each test case, print YES if the students can be split into two teams whose strengths differ by at most , and NO if they cannot. Print one answer per line.