Humpty Dumpty

3.8

10 votes
Problem

Humpty Dumpty lives on a two-dimensional plane. He likes to jump. Currently, he is located in the point (0, 0). He would like to reach the point (x, y). You are given the point x & y.

Humpty Dumpty wants to reach the desired destination in a specific way: using a series of jumps with pre-determined lengths. You are given these lengths in an array lengthOfJumps . You should determine whether Humpty Dumpty would be able to reach desired position using all of the jump lengths.

Note :

  • Humpty Dumpty can jump onto arbitrary points in the plane, they are not required to have integer coordinates.

Input :

The first line of input contains an integer T denoting the number of test cases.

Each test case contains an integer N denoting number of jumps, followed by second line of input containing two space separated integers x y. Now, N lines of input follows having an integer each where i th line denotes the lengthOfJumps[i]

Output :

Print "Able" (quotes for clarity) if Humpty Dumpty is able to reach his desired destination from (0, 0) using the desired sequence of jump lengths. Otherwise, print "Not able".

Constraints :

  • -1000 <= x, y <= 1000
  • 1 <= N <= 50
  • 1 <= lengthOfJumps[i] <= 1000
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

Case #1:

In this case, Humpty Dumpty can first jump from (0,0) to (0,1) then from (0, 1) to (0, 2) then again from (0, 2) to (0, 0)

Case #2:

In this case, Humpty Dumpty must make a jump of length exactly 2, followed by a jump of length exactly 5. One possibility is to jump from (0, 0) to (2, 0), and then from (2, 0) to (5, 4).

Case #3:

The distance from (0, 0) to (3, 4) is 5. You cannot get there using a single jump of length 4 - it is too short.

Editor Image

?