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 <- lines <$> getContents
  11. let (ps0, ms0) = splitAt n ls
  12. ms = map read $ take d ms0
  13. ps = map read ps0
  14. putStrLn $ unlines $ map show $ map (maxPair ps) ms
  15.  
  16. maxPair :: [Int] -> Int -> Int
  17. maxPair xxs p = f 0 =<< reverse $ sort xxs
  18. where
  19. f r (x:xs) (y:ys)
  20. | x == y = r
  21. | l > p = f r xs (y:ys)
  22. | otherwise = f (max l r) (x:xs) ys
  23. where l = x + y
  24. f r _ _ = r
  25.  
Success #stdin #stdout 0s 6348KB
stdin
5 2
4000
3000
1000
2000
5000
10000
3000
stdout
9000
3000