Count of distinct integers in range [ 1 , N ] that do not have any subset sum as K | C ++ program for the above approach ; Function to find maximum number of distinct integers in [ 1 , N ] having no subset with sum equal to K ; Declare a vector to store the required numbers ; Store all the numbers in [ 1 , N ] except K ; Store the maximum number of distinct numbers ; Reverse the array ; Print the required numbers ; Driver Code ; Given Input ; Function Call
#include <bits/stdc++.h> NEW_LINE using namespace std ; void findSet ( int N , int K ) { vector < int > a ; for ( int i = 1 ; i <= N ; i ++ ) { if ( i != K ) a . push_back ( i ) ; } int MaxDistinct = ( N - K ) + ( K / 2 ) ; reverse ( a . begin ( ) , a . end ( ) ) ; for ( int i = 0 ; i < MaxDistinct ; i ++ ) cout << a [ i ] << " ▁ " ; } int main ( ) { int N = 5 , K = 3 ; findSet ( N , K ) ; return 0 ; }