Maximum amount of money that can be collected by a player in a game of coins | C # Program to implement the above approach ; Function to calculate the maximum amount collected by A ; Stores the money obtained by A ; Stores mid elements of odd sized rows ; Size of current row ; Increase money collected by A ; Add coins at even indices to the amount collected by A ; Print the amount ; Driver code ; Function call to calculate the amount of coins collected by A
using System ; using System . Collections . Generic ; class GFG { static void find ( int N , List < List < int > > Arr ) { int amount = 0 ; List < int > mid_odd = new List < int > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { int siz = Arr [ i ] . Count ; for ( int j = 0 ; j < siz / 2 ; j ++ ) amount = amount + Arr [ i ] [ j ] ; if ( siz % 2 == 1 ) mid_odd . Add ( Arr [ i ] [ siz / 2 ] ) ; } mid_odd . Sort ( ) ; for ( int i = 0 ; i < mid_odd . Count ; i ++ ) if ( i % 2 == 0 ) amount = amount + mid_odd [ i ] ; Console . WriteLine ( amount ) ; } static void Main ( ) { int N = 2 ; List < List < int > > Arr = new List < List < int > > ( ) ; Arr . Add ( new List < int > ( ) ) ; Arr [ 0 ] . Add ( 5 ) ; Arr [ 0 ] . Add ( 2 ) ; Arr [ 0 ] . Add ( 3 ) ; Arr [ 0 ] . Add ( 4 ) ; Arr . Add ( new List < int > ( ) ) ; Arr [ 1 ] . Add ( 1 ) ; Arr [ 1 ] . Add ( 6 ) ; find ( N , Arr ) ; } }