Number of positions such that adding K to the element is greater than sum of all other elements | C ++ program to implement above approach ; Function that will find out the valid position ; find sum of all the elements ; adding K to the element and check whether it is greater than sum of all other elements ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int validPosition ( int arr [ ] , int N , int K ) { int count = 0 , sum = 0 ; for ( int i = 0 ; i < N ; i ++ ) { sum += arr [ i ] ; } for ( int i = 0 ; i < N ; i ++ ) { if ( ( arr [ i ] + K ) > ( sum - arr [ i ] ) ) count ++ ; } return count ; } int main ( ) { int arr [ ] = { 2 , 1 , 6 , 7 } , K = 4 ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << validPosition ( arr , N , K ) ; return 0 ; }