text: Split squares of first N natural numbers into two sets with minimum absolute difference of their sums | C # program for the above approach ; Function to partition squares of N natural number in two subset ; Store the count of blocks of size 8 ; Partition of block of 8 element ; Store the minimum subset difference ; Partition of N elements to minimize their subset sum difference ; Store elements of subset A and B ; If element is of type A ; If the element is of type B ; Print the minimum subset difference ; Print the first subset ; Print the second subset ; Driver Code ; Function Call
code: using System ; class GFG { static void minimumSubsetDifference ( int N ) { int blockOfSize8 = N / 8 ; string str = " ABBABAAB " ; int subsetDifference = 0 ; string partition = " " ; while ( blockOfSize8 -- > 0 ) { partition += str ; } int [ ] A = new int [ N ] ; int [ ] B = new int [ N ] ; int x = 0 , y = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( partition [ i ] == ' A ' ) { A [ x ++ ] = ( ( i + 1 ) * ( i + 1 ) ) ; } else { B [ y ++ ] = ( ( i + 1 ) * ( i + 1 ) ) ; } } Console . WriteLine ( subsetDifference ) ; for ( int i = 0 ; i < x ; i ++ ) Console . Write ( A [ i ] + " ▁ " ) ; Console . WriteLine ( ) ; for ( int i = 0 ; i < y ; i ++ ) Console . Write ( B [ i ] + " ▁ " ) ; } public static void Main ( string [ ] args ) { int N = 8 ; minimumSubsetDifference ( N ) ; } }