text: Find the subsequence with given sum in a superincreasing sequence | C # implementation of the approach ; Function to find the required subsequence ; Current element cannot be a part of the required subsequence ; Include current element in the required subsequence So update the sum ; Print the elements of the required subsequence ; If the current element was included in the subsequence ; Driver code
code: using System ; class GFG { static void findSubSeq ( int [ ] arr , int n , int sum ) { for ( int i = n - 1 ; i >= 0 ; i -- ) { if ( sum < arr [ i ] ) arr [ i ] = - 1 ; else sum -= arr [ i ] ; } for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] != - 1 ) Console . Write ( arr [ i ] + " ▁ " ) ; } } public static void Main ( String [ ] args ) { int [ ] arr = { 17 , 25 , 46 , 94 , 201 , 400 } ; int n = arr . Length ; int sum = 272 ; findSubSeq ( arr , n , sum ) ; } }