Distribute the number among k elements
temp = Sk / k ; rem = Sk % k ; if ( temp + rem >= l && temp + rem <= r ) { a [ i ] = temp ; } else if ( temp + rem > r ) { a [ i ] = r ; } else if ( temp + rem < r ) { cout << " - 1" ; return ; } Sk = Sk - a [ i ] ; k = k - 1 ; }