Check if the first K elements forms a number which is divisible by 3
for ( i = 0 ; i < k ; i ++ ) { sum += arr [ i ] ; } int found = 0 ; if ( sum % 3 == 0 ) { ans = make_pair ( 0 , i - 1 ) ; found = 1 ; }