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
#include <bits/stdc++.h> NEW_LINE using namespace std ; void canMake ( int n , int ar [ ] ) { int sum = 0 , maxx = -1 ; for ( int i = 0 ; i < n ; i ++ ) { sum += ar [ i ] ; maxx = max ( maxx , ar [ i ] ) ; } if ( n == 1 sum % 2 == 1 sum - maxx < maxx ) { cout << " No STRNEWLINE " ; } else { cout << " Yes STRNEWLINE " ; } } int main ( ) { int n = 6 ; int arr [ ] = { 1 , 1 , 2 , 3 , 6 , 11 } ; canMake ( n , arr ) ; return 0 ; }