Result

AC

Duration

871ms

Code [DL]

main=interact$unlines.(\(a:b)->zipWith min(scanl1 max$b!!0)(s a):b).s.lines
s(a:b)=a:scanr1 max b

stdin

                               T                  
                                                  
                                                  
                                                  
                                                  
        K                                         

stdout

        KKKKKKKKKKKKKKKKKKKKKKKK                  
        K                                         
        K                                         
        K                                         
        K                                         
        K                                         

stderr

strace