Check if it is possible to reach the point ( X , Y ) using distances given in an array | Function to check if the point ( 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 , print Yes ; Driver Code
function isPossibleToReach ( A , N , X , Y ) { let distance = Math . sqrt ( ( X * X + Y * Y ) ) ; let mx = 0 ; for ( let i = 0 ; i < N ; i ++ ) { mx += A [ i ] ; } if ( mx < distance ) { document . write ( " " ) ; return 0 ; } if ( ( mx - distance ) < 0.000001 ) { document . write ( " " ) ; return 0 ; } for ( let i = 0 ; i < N ; i ++ ) { if ( distance + mx < 2 * A [ i ] ) { document . write ( " " ) ; return 0 ; } } document . write ( " " ) ; return 0 ; } let A = [ 2 , 5 ] ; let X = 5 , Y = 4 ; let N = A . length ; isPossibleToReach ( A , N , X , Y ) ;