-
Notifications
You must be signed in to change notification settings - Fork 1
/
294_A.hs
25 lines (22 loc) · 1.09 KB
/
294_A.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
module Main where
import Control.Monad
shoot :: [Int] -> [Int] -> [Int]
shoot birds shot = let [wire, bird] = shot
birdsOnShotWire = birds!!(wire - 1)
birdsToMin = bird - 1
birdsToMax = birdsOnShotWire - birdsToMin - 1
totalWires = length birds
birdsDiff = (replicate (wire - 2) 0)
++ (if wire == 1
then [-birdsOnShotWire, birdsToMax]
else
if wire == totalWires
then [birdsToMin, -birdsOnShotWire]
else [birdsToMin, -birdsOnShotWire, birdsToMax])
++ (replicate (totalWires - wire - 1) 0)
in
zipWith (+) birds birdsDiff
main = do
birds <- liftM (map read . words) (getLine >> getLine)
shots <- liftM (map (map read . words) . lines) (getLine >> getContents)
mapM_ print $ foldl shoot birds shots