Data.Vector.Algorithms.Intro には sortBy がある
競プロ典型 90 問 14 日目 - We Used to Sing a Song Together(★3)
import Control.Monad
import qualified Data.ByteString.Char8 as C
import Data.List
import qualified Data.Vector.Algorithms.Intro as A
import qualified Data.Vector.Unboxed as U
main = sol <$> readLn <*> get <*> get >>= print
get = unfoldr (C.readInt . C.dropWhile (==' ')) <$> C.getLine
sol n as bs = U.sum $ U.zipWith ((abs .) . (-)) (f as) (f bs)
where
f = U.modify (A.sortBy compare) . U.fromListN n
いいなと思ったら応援しよう!
ありがとう