import Data.List (sort, intersperse)

main :: IO ()
main = do
  [n, k] <- map read . words <$> getLine
  ps <- map read . words <$> getLine
  qs <- map read . words <$> getLine
  let
    as = map show $ g k ps qs
    a : as' = as
  putStr a
  mapM_ putStr . map (' ' :) $ as'
  putStrLn ""

f :: [Int] -> [Int] -> [Int]
f ps qs = map snd . sort $ zip ps qs

g k ps qs = if k == 1 then ps else g (k - 1) qs (f ps qs)
