Check if it is possible to reach the point ( X , Y ) using distances given in an array | C # program for the above approach ; 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
import java . io . * ; class GFG { static int isPossibleToReach ( int [ ] A , int N , int X , int Y ) { double distance = Math . sqrt ( ( X * X + Y * Y ) ) ; double mx = 0 ; for ( int i = 0 ; i < N ; i ++ ) { mx += ( A [ i ] ) ; } if ( mx < distance ) { System . out . print ( " NO " ) ; return 0 ; } if ( ( mx - distance ) < 0.000001 ) { System . out . print ( " YES " ) ; return 0 ; } for ( int i = 0 ; i < N ; i ++ ) { if ( distance + mx < 2 * A [ i ] ) { System . out . print ( " No " ) ; return 0 ; } } System . out . print ( " Yes " ) ; return 0 ; } public static void main ( String [ ] args ) { int [ ] A = { 2 , 5 } ; int X = 5 , Y = 4 ; int N = A . length ; isPossibleToReach ( A , N , X , Y ) ; } }