Check if it is possible to reach the point ( X , Y ) using distances given in an array | Python program for the above approach ; Function to check if the po ( X , Y ) is reachable from ( 0 , 0 ) or not ; Find the Euclidian Distance ; Calculate the maximum distance ; Case 1. ; Case 2. ; Otherwise , check for the polygon condition for each side ; Otherwise , prYes ; Driver Code
import math NEW_LINE def isPossibleToReach ( A , N , X , Y ) : NEW_LINE INDENT distance = math . sqrt ( X * X + Y * Y ) NEW_LINE mx = 0 NEW_LINE for i in range ( N ) : NEW_LINE INDENT mx += A [ i ] NEW_LINE DEDENT if ( mx < distance ) : NEW_LINE INDENT print ( " NO " ) NEW_LINE return 0 NEW_LINE DEDENT if ( ( mx - distance ) < 0.000001 ) : NEW_LINE INDENT print ( " YES " ) NEW_LINE return 0 NEW_LINE DEDENT for i in range ( N ) : NEW_LINE INDENT if ( distance + mx < ( 2 ) * ( A [ i ] ) ) : NEW_LINE INDENT print ( " No " ) NEW_LINE return 0 NEW_LINE DEDENT DEDENT print ( " Yes " ) NEW_LINE return 0 NEW_LINE DEDENT A = [ 2 , 5 ] NEW_LINE X = 5 NEW_LINE Y = 4 NEW_LINE N = len ( A ) NEW_LINE isPossibleToReach ( A , N , X , Y ) NEW_LINE