You are viewing a single comment's thread. Return to all comments →
Haskell
module Main where import Data.List (find, sortBy) import Data.Maybe (fromMaybe) overlapping :: Int -> [a] -> [[a]] overlapping k xs | length xs < k = [] | otherwise = take k xs : overlapping k (tail xs) solve :: [Int] -> [Int] solve xs = case firstValid of Just [x, y, z] -> [z, y, x] Nothing -> [-1] where xs' = sortBy (flip compare) $ filter (> 0) xs tripples = overlapping 3 xs' firstValid = find (\[x, y, z] -> x < y + z) tripples main :: IO () main = do _ <- getLine xs <- map read . words <$> getLine :: IO [Int] putStrLn $ unwords $ map show $ solve xs
Seems like cookies are disabled on this browser, please enable them to open this website
Maximum Perimeter Triangle
You are viewing a single comment's thread. Return to all comments →
Haskell