• + 0 comments

    Haskell

    module Main where
    
    import Data.List.Split (chunksOf)
    
    solve :: Int -> [Int] -> Int
    solve k arr =
        length -- count the True
            . filter id -- only the Trues
            . zipWith elem [1 ..] -- is the page number in the page?
            $ concatMap (chunksOf k . flip take [1 ..]) arr -- list of pages' contents
    
    main :: IO ()
    main = do
        [n, k] <- map read . words <$> getLine :: IO [Int]
        arr <- map read . words <$> getLine :: IO [Int]
        print $ solve k arr