fork download
  1. import Control.Applicative
  2. import Data.List
  3.  
  4. main :: IO ()
  5. main = inputOutput
  6.  
  7. inputOutput :: IO ()
  8. inputOutput = do
  9. [n, d] <- map read <$> words <$> getLine
  10. ls <- map read <$> lines <$> getContents
  11. let (ps, ms0) = splitAt n ls
  12. ms = take d ms0
  13. putStrLn $ unlines $ map show $ map (maxPair ps) ms
  14.  
  15. maxPair :: [Int] -> Int -> Int
  16. maxPair xxs p = f 0 =<< reverse $ sort xxs
  17. where
  18. f r (x:xs) (y:ys)
  19. | x == y = r
  20. | l > p = f r xs (y:ys)
  21. | otherwise = f (max l r) (x:xs) ys
  22. where l = x + y
  23. f r _ _ = r
  24.  
Success #stdin #stdout 0s 6348KB
stdin
4 3
8000
4000
9000
6000
3000
14000
10000
stdout
0
14000
10000