Result

AC

Duration

1129ms

Code [DL]

main=interact$unlines.scanl1(!).lines
a!b|(x,y)<-span(<'J')$zipWith max a b=x++scanr1 max y

stdin

                        T                         
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
        K                                         

stdout

                        T                         
                        T                         
                        T                         
                        T                         
                        T                         
                        T                         
                        T                         
                        T                         
                        T                         
                        T                         
                        T                         
                        T                         
                        T                         
                        T                         
                        T                         
                        T                         
        TTTTTTTTTTTTTTTTT                         

stderr

strace