Check if all elements of the given array can be made 0 by decrementing value in pairs | C # program to make the array zero by decrementing value in pairs ; Function to check if all the elements can be made 0 in an array ; Variable to store sum and maximum element in an array ; Loop to calculate the sum and max value of the given array ; If n is 1 or sum is odd or sum - max element < max then no solution ; For the remaining case , print Yes ; Driver code
using System ; class GFG { static void canMake ( int n , int [ ] ar ) { int sum = 0 , maxx = - 1 ; for ( int i = 0 ; i < n ; i ++ ) { sum += ar [ i ] ; maxx = Math . Max ( maxx , ar [ i ] ) ; } if ( n == 1 sum % 2 == 1 sum - maxx < maxx ) { Console . Write ( " No STRNEWLINE " ) ; } else { Console . Write ( " Yes STRNEWLINE " ) ; } } public static void Main ( String [ ] args ) { int n = 6 ; int [ ] arr = { 1 , 1 , 2 , 3 , 6 , 11 } ; canMake ( n , arr ) ; } }