Created
December 27, 2014 03:36
-
-
Save aiya000/c257c7a24c2fefea5608 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Control.Monad | |
| type Bar = [Int] | |
| type BarLen = Int | |
| type SelectLen = Int | |
| type Damage = Int | |
| main :: IO () | |
| main = getLengths >>= \(rLen,bLen) -> | |
| getBar bLen >>= \bar -> | |
| print $ criticalDamage bar rLen | |
| getLengths :: IO (BarLen,SelectLen) | |
| getLengths = getLine >>= | |
| return . map read . words >>= \(x:y:_) -> | |
| return (x,y) | |
| getBar :: BarLen -> IO Bar | |
| getBar n = replicateM n getLine >>= return . map read | |
| criticalDamage :: Bar -> SelectLen -> Damage | |
| criticalDamage xs n = foldr max 0 $ damages xs n | |
| where | |
| damages ys m = foldr (\a b -> fst a + snd a : b) [] $ zip ys (tail ys) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment