Possible arrangement of persons waiting to sit in a hall | 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
def findTheOrder ( arr , s , N ) : NEW_LINE INDENT ans = [ ] NEW_LINE A = [ [ ] for i in range ( N ) ] NEW_LINE for i in range ( N ) : NEW_LINE INDENT A [ i ] = [ arr [ i ] , i + 1 ] NEW_LINE DEDENT A = sorted ( A ) NEW_LINE q = [ ] NEW_LINE index = 0 NEW_LINE for i in range ( 2 * N ) : NEW_LINE INDENT if ( s [ i ] == '0' ) : NEW_LINE INDENT ans . append ( A [ index ] [ 1 ] ) NEW_LINE q . append ( A [ index ] ) NEW_LINE index += 1 NEW_LINE DEDENT else : NEW_LINE INDENT ans . append ( q [ - 1 ] [ 1 ] ) NEW_LINE del q [ - 1 ] NEW_LINE DEDENT q = sorted ( q ) NEW_LINE DEDENT for i in ans : NEW_LINE INDENT print ( i , end = " ▁ " ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT N = 3 NEW_LINE arr = [ 2 , 1 , 3 ] NEW_LINE s = "001011" NEW_LINE findTheOrder ( arr , s , N ) NEW_LINE DEDENT