Possible arrangement of persons waiting to sit in a hall | C # program for the above approach ; Function to find the arrangement of seating ; Stores the row in which the ith person sits ; Stores the width of seats along with their index or row number ; Sort the array ; Store the seats and row for boy 's seat ; Stores the index of row upto which boys have taken seat ; Iterate the string ; Push the row number at index in vector and heap ; Increment the index to let the next boy in the next minimum width vacant row ; Otherwise ; If girl then take top of element of the max heap ; Pop from queue ; Print the values ; Driver code ; Given N ; Given arr [ ] ; Given string ; Function Call
using System ; using System . Collections . Generic ; class GFG { static void findTheOrder ( int [ ] arr , string s , int N ) { List < int > ans = new List < int > ( ) ; Tuple < int , int > [ ] A = new Tuple < int , int > [ N ] ; for ( int i = 0 ; i < N ; i ++ ) A [ i ] = new Tuple < int , int > ( arr [ i ] , i + 1 ) ; Array . Sort ( A ) ; List < Tuple < int , int > > q = new List < Tuple < int , int > > ( ) ; int index = 0 ; for ( int i = 0 ; i < 2 * N ; i ++ ) { if ( s [ i ] == '0' ) { ans . Add ( A [ index ] . Item2 ) ; q . Add ( A [ index ] ) ; q . Sort ( ) ; q . Reverse ( ) ; index ++ ; } else { ans . Add ( q [ 0 ] . Item2 ) ; q . RemoveAt ( 0 ) ; } } foreach ( int i in ans ) { Console . Write ( i + " ▁ " ) ; } } static void Main ( ) { int N = 3 ; int [ ] arr = { 2 , 1 , 3 } ; string s = "001011" ; findTheOrder ( arr , s , N ) ; } }