-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclouds.hs
More file actions
19 lines (16 loc) · 718 Bytes
/
clouds.hs
File metadata and controls
19 lines (16 loc) · 718 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import Control.Applicative
solve :: Integer -> [Integer] -> Integer
solve k clouds =
let
traverseClouds energy cloud =
if next_cloud == 0
then new_energy
else traverseClouds (new_energy - 1) next_cloud
where cloud_energy = if clouds !! fromIntegral cloud == 0 then 0 else -2
new_energy = energy + cloud_energy
next_cloud = (cloud + k) `mod` (fromIntegral (length clouds))
in (traverseClouds 100 0) - 1
main = do
[n, k] <- map read <$> words <$> getLine
clouds <- map read <$> take (fromIntegral n) <$> words <$> getLine
putStrLn $ show $ solve k clouds