You are viewing a single comment's thread. Return to all comments →
Haskell, most obtuse solution? :-p
module Main where import Control.Monad (replicateM_) import Data.List (nub, singleton, sort) import qualified Data.Map as M import Data.Maybe (catMaybes) solve ns k = let nlocs = zip ns $ map singleton [1 ..] mlocs = M.fromListWith (++) nlocs sols = M.foldlWithKey (\acc x locs -> fmap (++ locs) (mlocs M.!? (k - x)) : acc) [] mlocs sol = head $ catMaybes sols -- we're guaranteed a unique solution in unwords $ map show $ sort $ nub sol main :: IO () main = do cases <- readLn :: IO Int replicateM_ cases $ do k <- readLn :: IO Int _ <- getLine ns <- map read . words <$> getLine :: IO [Int] putStrLn $ solve ns k
Seems like cookies are disabled on this browser, please enable them to open this website
Ice Cream Parlor
You are viewing a single comment's thread. Return to all comments →
Haskell, most obtuse solution? :-p