Minimum number of Circular obstacles required to obstruct the path in a Grid | C # program to find the minimum number of obstacles required ; Function to find the minimum number of obstacles required ; Find the minimum range required to put obstacles ; Sorting the radius ; If val is less than zero then we have find the number of obstacles required ; Driver code
using System ; class GFG { static int solve ( int n , int m , int obstacles , double [ ] range ) { double val = Math . Min ( n , m ) ; Array . Sort ( range ) ; int c = 1 ; for ( int i = obstacles - 1 ; i >= 0 ; i -- ) { range [ i ] = 2 * range [ i ] ; val -= range [ i ] ; if ( val <= 0 ) { return c ; } else { c ++ ; } } if ( val > 0 ) { return - 1 ; } return 0 ; } public static void Main ( ) { int n = 4 , m = 5 , obstacles = 3 ; double [ ] range = { 1.0 , 1.25 , 1.15 } ; Console . WriteLine ( solve ( n , m , obstacles , range ) ) ; } }