fork download
  1. import Data.Function (on)
  2. import Data.List (sortBy, groupBy, minimumBy)
  3. import Data.Ord (comparing)
  4. (|>) x f = f x
  5.  
  6. solve xs ys =
  7. let partialSum s (y,x) = s - x *2 + 1 in
  8. zip ys xs
  9. |> sortBy (comparing fst)
  10. |> groupBy (on (==) fst)
  11. |> scanl (\s x -> (fst s + foldl partialSum 0 x, fst $ head x)) (foldl1 (+) xs, minimum ys - 1)
  12. |> minimumBy (comparing fst)
  13. |> snd
  14.  
  15. x1 = [0, 0, 0, 1, 1, 1]
  16. y1 = [6, 3, 4, 4, 4, 2.1]
  17. main = print $ solve x1 y1
Success #stdin #stdout 0s 4696KB
stdin
Standard input is empty
stdout
2.1